• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

How to customize the 404 error page for Tomcat

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to customize 404 error page for Tomcat server. Sometimes, this is very important because you may need to redirect the specific request to special error page. Sure, you can add the 404 error page in your web.xml, however, this is not customized page because it doesn't know what is the original request. I know, you can customize a 404 error page for Apache server by knowing what are the original requests, like it was mentioned in: Custom Error Pages with PHP and Apache. My question is that if you cann't configure your Apache server but Tomcat, what I can do to customize the 404 error pages? Thanks
[ August 06, 2003: Message edited by: William Chang ]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Tomcat forum.
 
Sheriff
Posts: 67503
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you can add the 404 error page in your web.xml, however, this is not customized page because it doesn't know what is the original request.


Sure it does. Since the error page is forwarded to from the request that causes the error, the request environment is still available. In fact, a number of request attributes are added to the request to help you create helpful customized error messages.
bear
 
Bear Bibeault
Sheriff
Posts: 67503
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, the relevant section of the Java Servlet 2.3 Specification is SRV.9.9.
And here's some not-so-subtle advice: if you are working with Tomcat or any other servlet engine and haven't read the Servlet Specification, you're doing it wrong!
Seriously, the spec may seem daunting but it's actually very well written, especially for a technical specification, and is an easy read. Do yourself a favor and get a copy from Sun's web site.
Keep the PDF handy, or even make a hard-copy for your desk.
hth,
bear
[ August 06, 2003: Message edited by: Bear Bibeault ]
 
William Chang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish that you have tried it by youself. Thanks.
 
William Chang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that I have not made myself clear. In your web.xml, you add:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
Whenever there is 404 error, e.g., the user type XXX.com/wrong_url, the tomcat will lead to /error.jsp. The error.jsp won't know where the 404 error comes from, I mean, because the user typed wrong_url. If you know, please let me know. Thanks.
[ August 09, 2003: Message edited by: William Chang ]
[ August 09, 2003: Message edited by: William Chang ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic