Cannot create a session after the response has been committed错误的原因

        今天练习时遇到了这个异常,貌似还挺常见的,于是百度了一下有关该异常的所有可能性:

2013-10-28 12:19:18 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
	at org.apache.catalina.connector.Request.doGetSession(Request.java:2313)
	at org.apache.catalina.connector.Request.getSession(Request.java:2074)
	at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
	at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:844)
	at com.demo.filter.LogFilter.doFilter(LogFilter.java:35)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.demo.filter.CharacterFilter.doFilter(CharacterFilter.java:24)
	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:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:619)

 

可能原因:
1.resp一旦返回(调用有关resp的方法),就不能再获得请求的session值(网上有说是sessionID被销毁了),那么在resp后就禁止getSession之类的方法,否则出错。

2.filter里的chain.doFilter()后没有返回语句,一说是安全,但不一定是在chain.doFilter()后就要返回,总之在最后没有任何操作了之后,还是return;一下好。

3.这个应该是我的程序抛出异常的原因,sql语句写错了。

4.(这个不知道是不是,没测试过)该写成getParameter()的地方写成getAttribute()了。

时间紧,很多都是查出来的,没有验证,这种学习态度不行,但实在没办法

你可能感兴趣的:(Cannot create a session after the response has been committed错误的原因)