aspose file tools*
The moose likes Struts and the fly likes customized error page in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "customized error page in struts" Watch "customized error page in struts" New topic
Author

customized error page in struts

annu joseph
Greenhorn

Joined: Nov 25, 2008
Posts: 16
Hi all,
i want to display a customized error page whenever some error occurs, how do i do this in struts??
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
you can do it in the web.xml file by specifying the <error-page> tag

you can specify the error code such as 404 or you can specify the type of exception

<error-page>
<error-code>404</error-code>
<location>/errorPagePath.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorPagePath.jsp</location>
</error-page>


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
annu joseph
Greenhorn

Joined: Nov 25, 2008
Posts: 16
simply mentioning this code in web.xml will do or do i need to add something else to the jsp pages too??? thanks in advance
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
you have to add the following directive to you custom error page

<%@ page isErrorPage="true" %>

so that you will have access to the implicit exception object.


if you specify more than one error page you can specify in your jsp pages to which error page to redirect in case some exception happens using the following page directive :

<%@ page errorPage="/pathToErrorPage"%>

however if you have only one error page there is no need to define it in your JSP's
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

annu joseph wrote:Hi all,
i want to display a customized error page whenever some error occurs, how do i do this in struts??


Struts provided a class "ExceptionHandler" which handles all the exception coming from your struts action class.
For this, you need to define a customized subclass with its entry in struts-config.xml.

Look here for detailed theory.




[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: customized error page in struts