Response has aready been committed

落花浮王杯 提交于 2020-01-11 12:42:30

问题


I have a cancel button which used to just refresh values. Now I have converted them to refresh or reload the page and move to Read-Only page. So changed cancel button to call a function like this,

function chkArea(){

        var url='<c:out value="${model.contextPath}"/>/abcHandler.do?operation=view;
        document.forms[0].action=url;
        document.forms[0].submit();
    }

Now when I submit cancel, I get the following message in the UI,

java.lang.IllegalStateException: Response has already been committed    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.EvermindHttpServletResponse.resetBuffer(EvermindHttpServletResponse.java:1892)    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:249)  at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:51) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:193) at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)........

and the console shows the following error:

javax.servlet.ServletException: The "url" attribute illegally evaluated to "null" or "" in &lt;import&gt;
    at com.evermind.server.http.EvermindPageContext.handlePageThrowable(EvermindPageContext.java:899)
    at com.evermind.server.http.EvermindPageContext.handlePageException(EvermindPageContext.java:816)

I don't see any error in the JS or JSP. What seems to be wrong? any suggestions?


回答1:


Firstly, the problem is not in the JSP or JS in your example1. The problem is in what your servlet does when it gets the ".../abcHandler.do?operation=view;" request.

The problem is that you are trying to do stuff that would require a change to the HTTP response headers ... after the headers have been sent. That is what the exception / message is saying. (A response is "committed" once the servlet framework starts writing the response. That is typically triggered when something opens the servlet output stream / writer ... in preparation to writing the response body.)

To give you a proper diagnosis, and sensible advice on how to fix the specific problem here, we need to see the Servlet / JSP code that is handling the above request.

The "url illegally evaluated to null" message is a bit hard to place. It could be happening before the IllegalStateException ... or after it.

(One possibility is that your JSP code is trying to do something with some 'url' attribute that is unexpectedly null, that is triggering an exception. Then the container's error handler is trying to set a different response status ... and that is failing because the response is already committed.)

In summary, it is not possible to figure out what the root problem is without more information; i.e. the code.


1 - Actually, you are missing a closing quote for the url initialization ... but I assume that's just a transcription error.




回答2:


This error comes when you are writing on the output stream from jsp and then again performing some operation on it. This causes IllegalStateException. You should not perform any operation when the response is already committed. By committed, I mean the response is sent back to the client. A common scenario is

 OutputStream stream = response.getOutPutStream();
  stream.write("something here");
  stream.flush();
 RequestDispatcher rd = request.getRequestDispatcher("someFile.jsp");
   rd.forward(request, response); // You can't do this because stream is already written


来源:https://stackoverflow.com/questions/17288481/response-has-aready-been-committed

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