Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher forward and IllegalStateException  RSS feed

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the following code does not result in IllegalStateException.



When I request This servlet it prints First Line but I was expecting IllegalStateException.

Java Servlet docs Calling flush() on the PrintWriter commits the response.



Java Servlet docs on forward method If the response already has been committed, this method throws an IllegalStateException.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to create such an exception? This is not a useful exercise, in my opinion.

The servlet implementation will decide whether it needs to throw the exception or not.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am studying for certification exam ,so I need to know.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that it is because the forward does not care whether or not the first part of the response has been sent.

Processing a forward just continues with the response object.

Bill
(searching the Tomcat 7 source code findes a WHOLE LOT (440 lines) of IllegalStateException being thrown locations.)
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



When I access this servlet it prints the contents of hello.jsp . and when is response sent to client after that you don`t have any way to write to response.
First of all why it does not result in IllegalStateException


Second This code from HFSJ page no. 205.


The above code does produce IllegalStateException
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!