Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle JSP exceptions declaratively

 
Neeraj Singhal
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to handle JSP exceptions declaratively through web.xml ?
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways to handle exception in JSP declarativly. Add the code in web.xml.
First:
In this you can define http error code

Second
In this you can define Exception Type

To help the error handler JSP analyze the problem and generate a detailed response, the servlet container sets certain attributes in the request before dispatching it to the error page. Like
javax.servlet.error.exception_type Contains the Class object for the
uncaught exception
[ March 03, 2004: Message edited by: Prakash Dwivedi ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The suggestion from Prakash can also be used for Servlets, not only JSPs.
Nick.
 
Neeraj Singhal
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had already tried these....but of no help
<error-page>
<error-code>*</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
whenever an exception occurs in jsp page....
the browser says...page cannot be displayed.
 
Neeraj Singhal
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgot to mention.....
I am using this with struts. Is it possible that this behaviour is happening due to that.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Struts is used, then you should not define the error in web.xml.
Instead, you should handle the exception in the struct-config-xxx.xml file, add the local exception to the config, so that corresponding page can be re-directed to .
Nick.
 
Neeraj Singhal
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, through struts-config.xml, we can handle validation errors only.
How can we handle runtime exception (JasperException) and redirect to some error page.
 
Ralph Cook
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever figure out how to do this?

rc
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic