java.lang.IllegalStateException解决办法

在做登陆验证及权限设置的时候,遇到了java.lang.IllegalStateException异常,经各种查证终于找到解决办法。

刚开始的错误是"java.lang.IllegalStateException: Cannot forward after response has been committed “,

查资料说当你有多个跳转的页面的语句时候,好好检查一下,当 转发 或者 重定向的时候,需要在response.sendRedirect("/login.jsp")后加一个retrun 即可。后来只在第二个调用的后边加上return后,错误变成

java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at neusoft.team10.servlet.LoginServlet.doPost(LoginServlet.java:90)
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:102)
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:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

只有把每个转发或重定向后边都加上return才可以,或者你只转发一个是肯定可以的;

 

posted on 2013-09-14 23:02  273度  阅读(5921)  评论(0编辑  收藏  举报

导航