Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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."
I agree. Here's the link:
subject: handle exception in servlet
It's not a secret anymore!