java.lang.IllegalStateException: Cannot create a session after the response has been committed

假装没事ソ 提交于 2019-12-28 07:09:14

问题


I've got this really strange request for an invalid URL on:

Invalid URL: /cgi-bin/1st.cgi

This is causing the following error:

 SEVERE: Exception initializing page context
java.lang.IllegalStateException: Cannot create a session after the response has been committed
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2381)
        at org.apache.catalina.connector.Request.getSession(Request.java:2098)
        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
        at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
        at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
...

How can I solve this issue?


回答1:


What's happening is the response stream has been closed. Either you already sent a redirect, or committed some other type of response. I recommend getting your session object before you perform any response, and save the response until there is nothing left to do with the HttpServletRequest or HttpServletResponse objects.

A good practice is to return from your Servlet right away after performing a redirect, that way you can avoid some of these problems.




回答2:


I had this problem because of multiple tag <h:outputScript target="head">



来源:https://stackoverflow.com/questions/4393160/java-lang-illegalstateexception-cannot-create-a-session-after-the-response-has

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!