aspose file tools*
The moose likes JSP and the fly likes How to handle JSP exceptions declaratively Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to handle JSP exceptions declaratively" Watch "How to handle JSP exceptions declaratively" New topic
Author

How to handle JSP exceptions declaratively

Neeraj Singhal
Ranch Hand

Joined: Aug 13, 2000
Posts: 49
Is it possible to handle JSP exceptions declaratively through web.xml ?
Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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 ]

Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
The suggestion from Prakash can also be used for Servlets, not only JSPs.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Neeraj Singhal
Ranch Hand

Joined: Aug 13, 2000
Posts: 49
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

Joined: Aug 13, 2000
Posts: 49
forgot to mention.....
I am using this with struts. Is it possible that this behaviour is happening due to that.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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

Joined: Aug 13, 2000
Posts: 49
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

Joined: May 29, 2005
Posts: 479
Did you ever figure out how to do this?

rc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle JSP exceptions declaratively
 
Similar Threads
how to handle ejb exception in jsp
handling EJB Exception in JSP
exception in struts handling in JSP
how to handle the runtime exceptions in jsp
user friendly errors?