问题描述:
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward
(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward
(ApplicationDispatcher.java:302)
Dec 17, 2012 7:21:15 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet SelectServlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward
(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward
(ApplicationDispatcher.java:302)
at com.servlet.SelectServlet.doPost(SelectServlet.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest
(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward
(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward
(ApplicationDispatcher.java:302)
at com.servlet.LoginServlet.doPost(LoginServlet.java:77)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
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:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process
(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
at com.servlet.SelectServlet.doPost(SelectServlet.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest
(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward
(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward
(ApplicationDispatcher.java:302)
at com.servlet.LoginServlet.doPost(LoginServlet.java:77)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
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:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process
(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
错误重点截取:
org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet SelectServlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
解决方案:
A common misunderstanding among starters is that they think that the call of a forward() or a sendRedirect() would magically exit and "jump" out of the method block, hereby ignoring the remnant of the code. For example:
protected void doPost() {
if (someCondition) {
sendRedirect();
}
forward(); // This is STILL invoked when someCondition is true!
}
This is thus actually not true. They do certainly not behave differently than any other Java methods (expect of System#exit() of course). When the someCondition in above example is true, then the chance is big that you will get an IllegalStateException: Cannot forward after response has been committed. This is regardless of whether the if statement calls a sendRedirect() or a forward().
To fix this, you need to add a return; statement afterwards
protected void doPost() {
if (someCondition) {
sendRedirect();
return;
}
forward();
}
... or to introduce an else block.
protected void doPost() {
if (someCondition) {
sendRedirect();
} else {
forward();
}
}
To naildown the root cause in your code, just search for any line which calls a sendRedirect() or a forward() without exiting the method block or skipping the remnant of the code. This can be inside the same servlet before the particular code line, but also in any servlet or filter which was been called before the particular servlet.
添加else语句或者添加return ;
分享到:
相关推荐
NULL 博文链接:https://hw1287789687.iteye.com/blog/1925191
纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....
1、错误信息 异常:Caused by: java.lang....Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.iot.framework.core.response.CommResponse ...
NULL 博文链接:https://anminer.iteye.com/blog/845067
1. java.lang.IllegalStateException: No wrapped connection. 2.java.lang.IllegalStateException: Adapter is detached. 原因: 1.单线程一次执行一个请求可以正常执行,如果使用多线程,同时执行多个请求时就会...
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but...
解决java.lang.IllegalStateException: unread block data的架包
Type 异常报告 消息 Failed to convert ... nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date': no matching editors or co
spring 总的概述。。。入门好教程~~~~~~~~~~~~~
IllegalStateException: The specified child already has a parent.我的博客中有文章讲解
weblogic12c部署webservice错误问题WSSERVLET11: 无法解析运行时描述符: java.lang.IllegalStateException: MASM0001:
Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath.:java.lang.IncompatibleClassChangeError: class ...
各种数据库在JDBC中的连接方法.及在struts与hibernate中的配置..
因工作的缘故,有机会接触了Java本地方法调用(JNI)。本文中记下了初试JNI的过程和一点点体会。 使用Java的JNI调用C/C++的动态联结库有个固定的步骤,下面将以一个最简单的HelloWorld例子程序来说明调用过程。这个...
这个存储库提供了一种在处理片段传输和后台任务时避免“java.lang.IllegalStateException:Can not perform this action after onSaveInstanceState”的方法。 您可以在的非常权威的阅读有关该问题和可能的解决方案...
今天公司springboot项目准备部署到...java.lang.IllegalStateException: 启动子级时出错 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720) at org.apache.catalina.core.Con
SteganoImage 1.0 绿色版
里面包含了java通过xfire访问webservice用到的jar包,已经打包好了
主要介绍了java 实现websocket的两种方式实例详解,一种使用tomcat的websocket实现,一种使用spring的websocket,本文通过代码给大家介绍的非常详细,需要的朋友可以参考下
从excel导入数据到datawindow-转载