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 SendError function not throwing IllegalStateException 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 "SendError function not throwing IllegalStateException" Watch "SendError function not throwing IllegalStateException" New topic

SendError function not throwing IllegalStateException

Adri Smith
Ranch Hand

Joined: Jun 07, 2004
Posts: 76
I am surprise that this code is working well without throwing any exception:

public class errorServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println("Hello world");
out.println(" </BODY>");


I think this should raise the exception IllegalStateException because the method flushBuffer commits the response.

If we take a look in the API we can see this:

flushbuffer => A call to this method automatically commits the response
sendError => If the response has already been committed, this method throws an IllegalStateException

So why is this not happening ?

I am using Tomcat 5.0. is it Tomcat not compliant or I am misunderstandign something ?

thanks in advance,
Sivasundaram Umapathy
Ranch Hand

Joined: Aug 10, 2002
Posts: 360
Your servlet on resin produces "java.lang.IllegalStateException: forward() not allowed after buffer has committed." where as it runs well on Tomcat.

So this may be an instance of one more tomcat issue.

Infact, I suggest you to make a note of these violations and report to tomcat mailing lists(Offcourse check the bug database before to ensure that it is not reported already)

Co-Author - SCMAD Exam Guide - ISBN:9780070077881
Author - Java certification success, Part 4: SCEA
Adri Smith
Ranch Hand

Joined: Jun 07, 2004
Posts: 76
Thx to gave me your opinion about this point.

This help to make me more confindent I am not missing some points.

I will try after taking the exam to contact Tomcat if this is not reported yet.

Sivasundaram Umapathy
Ranch Hand

Joined: Aug 10, 2002
Posts: 360
All the best with your exam preparation
Adri Smith
Ranch Hand

Joined: Jun 07, 2004
Posts: 76
Thanks a lot

You are helping me very much in making things clear

I wish you all the best

This forum is wonderful !

I agree. Here's the link:
subject: SendError function not throwing IllegalStateException
Similar Threads
about sendRedirect
doubt in Exception occured by sendError()
Confused with flush() behavior
Servlet getParameter