• 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

customized error page in struts

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic