java.lang.IllegalStateException: Cannot forward after response has been committed

今天在测试的时候出现了这样的错误:
2010-10-12 21:07:17 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet DangAnServlet threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:313)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
 at com.yin.dangan.servlet.DangAnServlet.doGet(DangAnServlet.java:433)
 at com.yin.dangan.servlet.DangAnServlet.doPost(DangAnServlet.java:534)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at com.yin.dangan.filter.EncodingFilter.doFilter(EncodingFilter.java:24)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
 at java.lang.Thread.run(Thread.java:619)

在网上查了一下,百度给的提示是在Servlet中的request.getRequestDispatcher("/error.jsp").forward(request, response);的逻辑有问题,然后仔细检查了一下相应的Servlet中的相应的方法,看看了,果然是自己设计的逻辑出现了点问题~以后要注意在Servlet中用到request.getRequestDispatcher("/error.jsp").forward(request, response);时一定要if {} else {} 写完整,还有就是在逻辑上不要冲突!仔细!

最后,很高兴遇到这个问题!嘿嘿……以后不会再犯了!嘿嘿……

你可能感兴趣的:(java,生活,职场,测试,休闲)