File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes java.lang.IllegalStateException: Response already committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.lang.IllegalStateException: Response already committed" Watch "java.lang.IllegalStateException: Response already committed" New topic
Author

java.lang.IllegalStateException: Response already committed

mk yadav
Greenhorn

Joined: Dec 04, 2012
Posts: 5
this is my servlet



and i got this exception


Servlet failed with Exception
java.lang.IllegalStateException: Response already committed
at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1608)
at weblogic.servlet.internal.ServletResponseImpl.sendRedirect(ServletResponseImpl.java:834)
at com.diy.controller.LoginServlet.doPost(LoginServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)



Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Thats nice.

Response already committed means that
- you have called "response.flushBuffer()" or similar
- you have output more than the responses buffer and it has been automatically flushed for you.

Basically if you have already started writing out your response, you are committed. You can't change your mind and say "go over there" instead.
I can't see anywhere in the code you are outputting stuff, but you DO call out.close.
Where does this "out" come from? What have you been doing with it up until now?

Which one of these response.sendRedirects() corresponds to LoginServlet line 56?


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I believe that once you have called sendRedirect then the response is committed and you can't write anything else to it. In particular you can't call sendRedirect again. So my theory is that sendRedirect is called at line 12 (of the posted code) and again at line 27.

(Also I'm going to move this post from JSP to Servlets since it's about servlets.)
mk yadav
Greenhorn

Joined: Dec 04, 2012
Posts: 5
thanks....paul and stefan
 
Don't get me started about those stupid light bulbs.
 
subject: java.lang.IllegalStateException: Response already committed
 
Similar Threads
Unhandled exception in Stripes
java.lang.IllegalStateException: Response already committed
java.lang.IllegalStateException: Response already committed
cannot change charset from 'ISO-8859-1' to 'UTF-8'
Exception while Rendering Oracle ADF 11.1.2.3 page with Spring Web Flow 2.3.1 & JSF 2.0