aspose file tools*
The moose likes Servlets and the fly likes handle exception in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "handle exception in servlet" Watch "handle exception in servlet" New topic

handle exception in servlet

Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79
Please can you tell me how it is possible to send an error message to a jsp page from a servlet when an exception has been caught.
Say I have a class which creates a string to show a user-friendly error message. How can I get this to forward to myError.jsp as the exception class has no handle on the request or response objects for the
getServletContext().getRequestDispatcher( itsPage ).include ( itsRequest, itsResponse ) method?
many thanks
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

sure -- what if you declare the exception in your web.xml like this:

FYI you can do this same kinda thing for 404, 403 and other error codes by changing the <exception-type> element to <error-code>
[ May 28, 2003: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
John Dunn
Ranch Hand

Joined: Jan 30, 2003
Posts: 1108
Not quite what you asked for, but may be of use anyway...

"No one appreciates the very special genius of your conversation as the dog does."
jQuery in Action, 2nd edition
subject: handle exception in servlet
Similar Threads
about exception handling in EJB
passing exception in MVC model from servlet to JSP
Standard way of handling exception + Java Class + Servlet
Handling Exceptions in MVC +Command Pattern
Exception handling