java.lang.IllegalStateException:提交响应后无法创建会话 [英] java.lang.IllegalStateException: Cannot create a session after the response has been committed
问题描述
我收到了一个非常奇怪的无效 URL 请求:
I've got this really strange request for an invalid URL on:
Invalid URL: /cgi-bin/1st.cgi
这会导致以下错误:
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?
推荐答案
发生的情况是响应流已关闭.您已经发送了重定向,或者提交了其他类型的响应.我建议在执行任何响应之前获取会话对象,并保存响应直到与 HttpServletRequest
或 HttpServletResponse
对象无关.
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.
一个好的做法是在执行重定向后立即从您的 Servlet 返回,这样您就可以避免其中一些问题.
A good practice is to return from your Servlet right away after performing a redirect, that way you can avoid some of these problems.
这篇关于java.lang.IllegalStateException:提交响应后无法创建会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!