File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException in servlet

 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I'm receiving this error occasionally(1 out of 4 tries) especially when my servlet is passing quite an amount of data(request.setAttribute) to the JSP. But I this error is reported in my log and seem to happen in the servlet and not the JSP.


Jan 22, 2007 1:45:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet ViewTimeServ threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:313)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at ph.wp.http.controllers.ViewTimeController.doPost(ViewTimeController.java:112)
at ph.wp.http.controllers.ViewTimeController.doGet(ViewTimeController.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)




here is my code...




I tried searching the forums and google but nothing seems to be solve to my problem. The JSP also outputs a blank(white) screen. Thanks!
[ January 22, 2007: Message edited by: Timothy Sam ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 3901
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error usually means you have sent data to the user as if you were going to send them a page, but then redirected them afterward. I can't really say for sure which line is causing this, but I suspect it might have to do with the session variables being set. Can anyone else spot where he might be producing output to the user before a redirect?
 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Scott! Please help people! I can't seem to figure this on my own...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
126 is in bold.

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears to be the first forward, but I can't see anything else writing to the output, unless the Servlets are chained? I'd try changing the forward to an include to see what happens.
 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! Changing from

request.getRequestDispatcher(FORWARD_VIEW_TIME).forward(request, response);

to

request.getRequestDispatcher(FORWARD_VIEW_TIME).include(request, response);

doesn't eliminate the problem...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still get this:

java.lang.IllegalStateException: Cannot forward after response has been committed
??
Check you code compiled properly. It should be impossible with the code change. Unless I'm insane. It's possible, you know.
 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sir, it still does... I tried creating and deploying a new war file now and I still get the error. Would it be helpful if I posted my JSP? Here it is...



[Edit by Dave - broke up some crazy long lines]
[ January 23, 2007: Message edited by: David O'Meara ]
 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I seem to have a slightly different Exception with the above suggestion. It says that it cannot create a session...


Jan 23, 2007 8:07:58 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet ViewTimeServ threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2214)
at org.apache.catalina.connector.Request.getSession(Request.java:2024)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:831)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:842)
at ph.wp.http.controllers.ViewTimeController.doPost(ViewTimeController.java:45)
at ph.wp.http.controllers.ViewTimeController.doGet(ViewTimeController.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that it solves the problem, but from the API for getSession(boolean)

To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.


Something is definitely committing the response. It could be a filter, chained servlet or just an annoying exception, but it is happening. In your logs, is there ever any other exceptions displayed? Do you have any filters? Does this servlet get called internally (ie rather than directly from the client)?
 
Timothy Sam
Ranch Hand
Posts: 751
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something is definitely committing the response. It could be a filter,


nope... I don't have any filters...

[quote\chained servlet
I think I have one which is called atleast once. But it doesn't display any error on that servlet(the one being called before this servlet that produces errors, the error also only appear after several calls on the very first servlet I mentioned in this thread).

or just an annoying exception, but it is happening.

No other exception appear...


Does this servlet get called internally (ie rather than directly from the client)?


As I sad from my statement above. I do have one which sets something in the session. Here it is:



componentUrl's value would be a servlet url like:

t=/viewtime.do
[ January 23, 2007: Message edited by: Timothy Sam ]
 
Pankaj Patel
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply Delete all statement.
 
Palak Mathur
Ranch Hand
Posts: 322
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I am getting the following error:-

Servlet failed with Exception
java.lang.IllegalStateException: Cannot forward a response that is already committed
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:125)


I am calling the servlet from directly using url. The jsp after processing (using ejb) sets the session attribute and using RequestDispatcher forwards the response to a JSP page. While doing so, everything works fine but I get this exception on Portal Server. It doesn't hinders with any processing or anything else but may be it will create issue during integration. How to rectify this??
[ January 29, 2007: Message edited by: Palak Mathur ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic