• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to handle JSP exceptions declaratively

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to handle JSP exceptions declaratively through web.xml ?
 
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you ever figure out how to do this?

rc
 
reply
    Bookmark Topic Watch Topic
  • New Topic