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、原因还待研究。
推荐阅读
-
SEVERE: Servlet.service() for servlet [SpringMVC] in context with path [] threw exception ........
-
Servlet.service() for servlet default threw exception
-
Servlet.service() for servlet default threw exception
-
SEVERE: Servlet.service() for servlet [SpringMVC] in context with path [] threw exception ........
-
Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.LinkageError