java.lang.IllegalStateException: Cannot forward after response has been committed
程序员文章站
2022-07-15 12:04:58
...
java.lang.IllegalStateException: Cannot forward after response has been committed
~~ 我用ajax从后台向前传值的时候报了这个错, Cannot forward after response has been committed的意思是response已经提交了,不能再转向。原因:response多次提交或者是由于有页面显示后仍然含请求转向产生的,说白了就是程序在return之前就已经执行了。所以解决办法就是return null,就是不能在跳转到另外的页面~
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:326)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
at com.zking.framework.ActionServlet.doPost(ActionServlet.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.zking.easyui.util.EncodingFilter.doFilter(EncodingFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
代码如下:
action:
try {
List<Module> lst=imd.queryModule(module);
System.out.println(lst.size());
Map<String, Object> map=new HashMap<>();
map.put("listleb",lst);
String outStr=JSON.toJSONString(map);
response.getWriter().println(outStr);
response.getWriter().flush();
response.getWriter().close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
} ```
action
<action type="com.zking.easyui.action.ModuleAction" path="/moduleAction"></action>
ajax:
type:'post',
url:'moduleAction.action',
dataType:'json',
data:{
'methodName':'queryModule',
'pid':'-1'
},
async:false,
success:function(data){
console.log(data);
}
});
推荐阅读
-
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解读
-
java.lang.IllegalStateException: Cannot forward after response has been committed
-
Cannot call reset() after response has been committed
-
Hibernate项目报错:Cannot call sendError() after the response has been committed
-
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解读
-
Cannot forward after response has been committed问题分析及解决
-
Hibernate项目报错:Cannot call sendError() after the response has been committed
-
Cannot call sendError() after the response has been committed 错误记录
-
Cannot call sendError() after the response has been committed
-
错误提示:Cannot call sendError() after the response has been committed的解决方法