File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt in Exception occured by sendError() 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt in Exception occured by sendError()" Watch "doubt in Exception occured by sendError()" New topic
Author

doubt in Exception occured by sendError()

aleyx chow
Greenhorn

Joined: May 15, 2005
Posts: 16
Why the code followed doesnt occur an IllegalStateException?



the output on IE6.0 (tomcat5.5,jdk1.5,servlet2.4)is:

test sendError()
is committed?false
is committed?true
//the String "sendError() method is called." is not printed
//the page isnt displayed as a 404 error page
//an IllegalStateException isnt thrown

is the output meaning that:
after flushBuffer() is called, the response is committed and
after sendError() is called, the buffer is reset?
but why an IllegalStateException is NOT occured?

i read servlet2.4 api doc,it says:

public void sendError(int sc)
Throws:
java.io.IOException - If an input or output exception occurs
IllegalStateException - If the response was committed before this method call

but it still puzzled my brains, isnt the sendError() method called after the response is committed in my code? Why an Exception isnt thrown
[ August 18, 2005: Message edited by: aleyx chow ]

Oh,father,though im in the nutshell,i still the king of limitless space.<br /> <br />scjp 1.4,scwcd 1.4,scbcd 1.3
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
What web container do you use?
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi,

If you are using Tomcat look in the logs on my machine Tomcat5.0/logs/localhost_log.2005-08-18.txt shows an exception was thrown. I have used the code you provided above to get the exception.

Sorry I can't explian why you get the line - I also get it!
is committed?true


Mat
aleyx chow
Greenhorn

Joined: May 15, 2005
Posts: 16
hi,thx 4 your replies.

To Sergey Tyulkin: i used Tomcat 5.5 and the browser is IE 6.0

To Mat Williams:
yes, i also found the "throw exception" record in the tomcat log files, thank u for pointing out that, but in my thought, the result on the web browser would also display the follows:

HTTP Status 500 -
----------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.IllegalStateException
sp.Resser.doGet(Resser.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


i found the reason that the browser is blank is i called flushBuffer() before throw an exception.

will show the exception's details on the browser and record it in the blog files, but

will not show anything on browser.
Why?What's the mechainism of the servlet output stream to do this?
Maybe it's another question and i should post it as a new topic, but i think it is related to the old one.
thax.
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
When you call sendError(), you automatically close the response, and all data, passed after sendError() is ignored.
To show 404 page i think you should define <error-page> element in DD with 404 eror-code.
aleyx chow
Greenhorn

Joined: May 15, 2005
Posts: 16
thanx 4 u replay,:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in Exception occured by sendError()
 
Similar Threads
sendRedirect ( qsn from Study kit)
clear this
IllegalStateException
Tomcat variable behavior with IllegalStateException
For all SCWCD guys : Doubts