Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

customized error page in struts

 
annu joseph
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
annu joseph
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic