• Post Reply Bookmark Topic Watch Topic
  • New Topic

Illegal State Exception

 
S Zaidi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I frequently get the following message while executing my servlets:

java.lang.IllegalStateException
at org.apache.coyote.tomcat4.CoyoteResponseFacade.sendRedirect
(CoyoteResponseFacade.java:338)


There is a simple Javascript in the JSP that calls the method on the servlet when the button on the screen is clicked. The method throws in a few attributes in the session and calls the following line:

getResponse().sendRedirect("KCSSChangeTitle.jsp");

This is where I get the IllegalStateException.
We are using Tomcat version 4.1.30 running on Windows 2000 server.
Does anyone know what could be causing this?
Thanks!!
P.S: The other messages on the board about IllegalStateException are about commiting response but the message I get is a little different; hence I decided to start a new thread.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An IllegalStateException on a sendRedirect is almost always caused by a call to sendRedirect after data has already been sent to the browser.

If you have any output (including setting headers) before the sendRedirect, you will see this exception.
 
Dan Vos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S Zaidi:
There is a simple Javascript in the JSP that calls the method on the servlet when the button on the screen is clicked. The method throws in a few attributes in the session and calls the following line:

getResponse().sendRedirect("KCSSChangeTitle.jsp");

BTW, the above is not JavaScript, it is scriptlet and will be executed by the server hence the Exception.

You should only use such statement in the beginning of your JSP file before any output to web browser.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!