Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display a customized "Error 404" page?

 
calvin ho
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic