File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Tomcat variable behavior with IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Tomcat variable behavior with IllegalStateException" Watch "Tomcat variable behavior with IllegalStateException" New topic

Tomcat variable behavior with IllegalStateException

Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218

After the response is committed by out.flush(), why does response.sendError() not throw an IllegalStateException? Or is the exception thrown but not visible?
[ March 13, 2007: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Check your server's console for the exception. It won't show on the browser because, well, the response was already sent to the browser before the exception occurred.

A good workman is known by his tools.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
one can use the response.isCommited( ) as a precaution !

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
That's useful Niranjan.
Mark, i looked at the Tomcat console window to se if i could get an exception, but wasn't able to find any.

I'm facing a similar problem with the following code too:

I remember i had an IllegalStateException for the above, since i'm trying to forward after committing the response. This is also mentioned on Pg. 205 of K&b. But since today, i have stopped getiing the exception and "Got beer color" gets printed in the browser.

Why does Tomcat exhibit such variable behavior?
[ March 13, 2007: Message edited by: Aniket Patil ]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10032

Guys, is this an issue with Tomcat?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
I've read topics around here that mention that Tomcat isn't fully J2EE-compliant. I've switched to Resin now and i'm getting the expected results.

I'm able to get an IllegalStateException if i try to forward()/sendRedirect() after a flush().
The curious thing is, the text i am sending through flush() is getting printed to browser and THEN an exception is raised. With Tomcat (when i got the exception once), no text was printed.
[ March 14, 2007: Message edited by: Aniket Patil ]
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

is this an issue with Tomcat

It sounds like one. I've a few ranchers complaining about that recently.

[My Blog]
All roads lead to JavaRanch
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi Aniket,

I tried the code snippet that you gave on tomcat ver 5.0 and it did give me IllegalStateException. What I wanted to know from you is that, did you check your log files i.e the text file for the day you ran this code under logs folder? It should reflect IllegalStateException there.


Thanks,<br />-Rancy
I agree. Here's the link:
subject: Tomcat variable behavior with IllegalStateException
It's not a secret anymore!