jetty webSocket:java.lang.IllegalStateException:提交 [英] jetty webSocket : java.lang.IllegalStateException: Committed
问题描述
我在Web应用程序中使用Jetty Websockets.
I am using Jetty Websockets in my Web Application .
当我尝试重定向到注销jsp时,出现此错误
When i am trying to redirect to a logoff jsp , i am getting this error
oejs.ServletHandler:/test
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1069)
at javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:232)
at org.eclipse.jetty.http.gzip.GzipResponseWrapper.resetBuffer(GzipResponseWrapper.java:273)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:199)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:98)
这是我重定向的方式
RequestDispatcher rd = request.getRequestDispatcher("logoff.jsp");
rd.forward(request, response);
此错误无法重现,但是能否请您告诉我何时会发生??
This error is not reproduceble , but could you please tell me when it may occur??
推荐答案
java.lang.IllegalStateException:已提交
java.lang.IllegalStateException: Committed
我想我将对异常的含义提供更一般的解释.首先,Jetty应该为异常消息感到羞耻.除非开发人员已经知道它的实际含义,否则它几乎不会提供任何帮助.例外应该是这样的:
I thought I'd provide a more general explanation of what the exception means. First off, Jetty should be ashamed by the exception message. It provides little to no help to the developer unless they already know what it actually means. The exception should be something like:
java.lang.IllegalStateException:响应头已经发送.您要在发送内容后返回结果吗?
java.lang.IllegalStateException: Response headers have already been sent. Are you trying to return a result after sending content?
通常,您在拨打电话时会发生此异常:
Typically this exception happens when you go and call:
resp.getOutputStream(); // or getWriter()
,然后尝试进行重定向或其他操作:
and then later try to do a redirect or something:
resp.sendRedirect("/someOtherUrl");
// or
return new ModelAndView("redirect:/someOtherUrl");
一旦获得OutputStream
或Writer
,以便可以将正文字节写入客户端,Jetty必须提交响应并发送HTTP 200
和关联的标头,以便它可以开始返回正文字节.一旦发生这种情况,您就无法进行重定向,也不能对状态代码或标头进行任何其他更改.
Once you get the OutputStream
or Writer
so you can write body bytes to the client, Jetty has to commit the response and send the HTTP 200
and associated headers, so it can start returning the body bytes. Once that happens, you then can't do a redirect nor make any other changes to the status code or headers.
返回正文字节后,正确的做法是从处理程序中返回null
而不是ModelAndView(...)
,或者只是更改处理程序以返回void
.
The proper thing to do, once you return body bytes, is to return null
from the handler instead of a ModelAndView(...)
or just change the handler to return void
.
这篇关于jetty webSocket:java.lang.IllegalStateException:提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!