Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic