简体   繁体   English

将tomcat 7.0.59升级到7.0.61:提交响应后无法创建会话

[英]Upgrade tomcat 7.0.59 to 7.0.61 : Cannot create a session after the response has been committed

We are upgrading from Tomcat 7.0.59 to 7.0.61 and getting following error. 我们正在从Tomcat 7.0.59升级到7.0.61并收到以下错误。

This error occurs only when passing via Apache proxy (no SSL). 仅当通过Apache代理(无SSL)传递时,才会发生此错误。

When calling the Tomcat context from the browser (without Apache proxy) it works without problems. 从浏览器(没有Apache代理)调用Tomcat上下文时,它可以正常工作。

Has anyone experienced the same/similar problem ? 有没有人遇到过相同/相似的问题?

We did go through the changelog ( https://tomcat.apache.org/tomcat-7.0-doc/changelog.html ) but we could not find any change explaining this behavior in Tomcat 7.0.61 我们确实浏览了变更日志( https://tomcat.apache.org/tomcat-7.0-doc/changelog.html ),但是在Tomcat 7.0.61中找不到任何解释此行为的更改。

SEVERE: Servlet.service() for servlet [CaptchaServlet] in context with path [/cw] threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:3008)
    at org.apache.catalina.connector.Request.getSession(Request.java:2384)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:897)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:909)
    at be.servlet.CaptchaServlet.doGet(CaptchaServlet.java:127)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.ExpiresFilter.doFilter(ExpiresFilter.java:1175)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

The code concerned is: 有关的代码是:

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    HttpSession session = req.getSession();

    Captcha captcha = getNumberCaptcha(_width, _height, 5, Color.black);

    session.setAttribute(NAME, captcha);

    resp.setHeader("Cache-Control", "private,no-cache,no-store");
    resp.setContentType("image/png");


    // See https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues
    // Wrap insite MyImageIOOutputStream
    ImageIO.write(captcha.getImage(), "png", new MyImageIOOutputStream(resp.getOutputStream()));

    resp.getOutputStream().flush();
    resp.getOutputStream().close();

}

Before you start saying it is the ImageIO we did use the MyImageIOOutputStream as specified on the https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues . 在您开始说它是ImageIO之前,我们确实使用了https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues上指定的MyImageIOOutputStream。

We even tried with loading an image from File into a byte array and sending the byte array in the resonse (so no making use of ImageIO), but the problem remains the same. 我们甚至尝试将图像从File加载到字节数组中,然后以共振方式发送字节数组(因此不使用ImageIO),但是问题仍然相同。

It is surprising to find that this error occurs in Tomcat 7.0.61 but not in 7.0.59. 令人惊讶地发现此错误发生在Tomcat 7.0.61中,而不是7.0.59中。 The error basically says that you are creating a session after the header of the HTTP response has been sent. 该错误基本上表示您已在发送HTTP响应的标头之后创建会话。 This is a problem because the session requires cookies and the cookies are transferred in the HTTP response headers. 这是一个问题,因为会话需要cookie,并且cookie在HTTP响应标头中传输。 So it's too late to send the cookies. 因此,发送cookie太晚了。

Assuming that the CaptchaServlet is your code, the easiest solution is to create the session ( getSession() ) before your write any output in the servlet. 假设CaptchaServlet是您的代码,最简单的解决方案是在将任何输出写入Servlet之前创建会话( getSession() )。 Then you are on the safe side with any servlet container. 这样,您就可以安全地使用任何servlet容器。

I confirm that I have the same issue than you (in my particular case, 7.0.62 vs 7.0.59). 我确认与您有相同的问题(在我的特定情况下为7.0.62与7.0.59)。 My app works fine behind the apache proxy if Tomcat version is 7.0.59 but I have the same trace than you if I use 7.0.62 behind the proxy. 如果Tomcat版本为7.0.59,则我的应用程序在apache代理后面运行良好,但如果在代理后面使用7.0.62,则与您的跟踪相同。

In my opinion we should report it to Tomcat as soon as possible 我认为我们应该尽快将其报告给Tomcat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Struts 2:提交响应后无法创建会话 - Struts 2: Cannot create a session after the response has been committed 在提交响应后无法创建会话 - cannot create session after response has been committed spring @SessionAttributes和“在提交响应后无法创建会话” - spring @SessionAttributes and “Cannot create a session after the response has been committed” Tomcat 异常 提交响应后无法调用 sendError()? - Tomcat exception Cannot call sendError() after the response has been committed? JSF 2.2 java.lang.IllegalStateException:提交响应后无法创建会话 - JSF 2.2 java.lang.IllegalStateException: Cannot create a session after the response has been committed Spring java.lang.IllegalStateException:在提交响应后无法创建会话 - Spring java.lang.IllegalStateException: Cannot create a session after the response has been committed 错误IllegalStateException对于大型数据集提交响应后,无法创建会话 - Error IllegalStateException Cannot create a session after the response has been committed for large data set Spring RedirectAttributes导致“在提交响应后无法创建会话”错误 - Spring RedirectAttributes results in “Cannot create a session after the response has been committed” error java.lang.IllegalStateException - 在提交响应后无法创建会话 - java.lang.IllegalStateException - Cannot create a session after the response has been committed 由于已提交响应,因此无法创建会话 - Failed to create a session, as response has been committed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM