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
Joined: May 10, 2005
What web container do you use?
Joined: Jul 20, 2005
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!
Joined: May 15, 2005
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.
Joined: May 10, 2005
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.