`
小胖vs小猪
  • 浏览: 61577 次
  • 性别: Icon_minigender_2
  • 来自: 长沙
社区版块
存档分类
最新评论

Servlet.service() for servlet default threw exception

阅读更多

在运用struts2+jquery+ajax返回json类型数据时,调试过程中报错:

严重: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
虽然可以正常运行,但是始终想弄清楚是为什么。过程是这样的:

1、前台index.jsp通过jquery ajax调用后台action将后台得到的数据以json类型返回到前台。前台调用代码:

function getSysInfo() {   
    $.getJSON("sysinfo_jsonSysinfo.action",function(data){
    var sHTML = "";   
        $.each(data,function(i,value){
       ...
     });
        $("#quecontent").html(sHTML);
    });
}

2、后台jsonSysinfo方法代码:

public String jsonSysinfo(){
        page = sysInfoService.searchForPage(page, sysInfoPOJO);
        HttpServletResponse response= ServletActionContext.getResponse();
       
         list=new ArrayList <SysInfoPOJO>();
         list = (List<SysInfoPOJO>) page.getResultList();
        JSONArray jsonArray = JSONArray.fromObject(list);
        PrintWriter out =null;
        response.setContentType("text/html;charset=utf-8");
        try{
            out=response.getWriter();
            out.print(jsonArray);
            out.flush();
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            out.close();
        }
        return "list";
    }

3、解决办法:在iteye上找到一个类似的情况,将return "list"修改为return null;即可。

4、原因还待研究。

分享到:
评论
2 楼 zjtprince 2012-08-03  
谢谢分享,我也纳闷,为什么要返回null?
1 楼 LiHu0512 2012-07-19  
不错,帮我解决了这个问题!想出来原因能否分享一下,为什么要返回null,不能返回其它值了?

相关推荐

Global site tag (gtag.js) - Google Analytics