Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendError works through Exception?

 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we call sendError(<error_code>, <error_message>

Internally is it that ServletException is raised with the suitable message and that is how we get to see the Errorpage with the error no. ?

FYI: Just another point,I just read somewhere that sendRedirect allows the service method to complete execution whereas in the case of forward the control moves out immediately to the page specified. - Interesting nah?. Though I have yet to test this.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the API, it does not raise an Exception.

The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
[ September 02, 2006: Message edited by: Satou kurinosuke ]
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of sendRedirect whether full service method executes or not , it does not matter . Browser simply sees the reponse code (301) and takes the new location from the Location header . The content in the response body is completly ignored.

However in case of forward , if we allow the entire service method to execute, it might result in IllegalStateException.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

sendError goes through the error page mechnism. That is if the error pages not configured in the web.xml, the error page generated by container is sent to client for the error code given in the sendError method. If the error page is defined in the web.xml, the particular page is called.

In both case of forward and redirect, the service method of the calling servlet execute after the forward or redirect call. Only the response output is closed at this stage, so if you try to write anything to the response, It will do nothing as the response is already closed.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic