my dog learned polymorphism*
The moose likes Servlets and the fly likes How to display a customized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to display a customized "Error 404" page?" Watch "How to display a customized "Error 404" page?" New topic
Author

How to display a customized "Error 404" page?

calvin ho
Greenhorn

Joined: Mar 13, 2001
Posts: 9
I want to know if there are any ways to display a customized "Page No Found" page whenever the user references a non-existent jsp?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by calvin ho:
I want to know if there are any ways to display a customized "Page No Found" page whenever the user references a non-existent jsp?

I think this is application server dependent.
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
I think you can have a custom error page for this purpose, and based on some check/validation, at the beginning of each JSP,forward the user to that error page.
Regards,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Yes, the servlet specification provides a specific means of doing this:
<web-app>
...
<error-page>
<error-code>404</error-code>
<location>/MyCustomErrorPage.html</location>
</error-page>
...
</web-app>
All Servlet 2.2 or 2.3 compliant containers are required to implement this. Note that this entry must be in the correct place in the web.xml, after all the <servlet> and <servlet-mapping> elements.
It is worth downloading the DTD and looking through it. There are a number of features available that are not widely known. You can download it from
http://java.sun.com/j2ee/dtds/web-app_2_2.dtd
The servlet 2.3 DTD is found at
http://java.sun.com/dtd/web-app_2_3.dtd

------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display a customized "Error 404" page?
 
Similar Threads
Customized Error message display
customized error page in struts
Page Directive errorPage and isErrorPage
No action config found for the specified url.
Displaying time inside a table cell