wood burning stoves*
The moose likes JSP and the fly likes Catching exceptions in JSP when they occur in Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Catching exceptions in JSP when they occur in Servlets" Watch "Catching exceptions in JSP when they occur in Servlets" New topic
Author

Catching exceptions in JSP when they occur in Servlets

Mike Landis
Greenhorn

Joined: Jun 05, 2003
Posts: 21
Hello,
I have a MVC model 2 based Web application.
My simple problem is that if servlet or action class
is throwing an Exception, my jsp file does not show
errorpage that is defined into Web.xml.
What could be wrong or what could be a better way to
bring up exception occured in servlet/action to jsp
errorpage.
Br
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

If you are throwing the exception from your servlet, of course it is not going to pick up the error page directive from a JSP that you haven't forwarded to yet.
One way to deal with this could be: in the event of an exception, forward to the error page yourself by catching the exception.
If you want your exception to be available on the error page via the 'exception' variable, add the exception as a request attribute with a key of 'javax.servlet.jsp.jspException'.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Landis
Greenhorn

Joined: Jun 05, 2003
Posts: 21
Thanks, it started to work!
br
Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catching exceptions in JSP when they occur in Servlets