Tomcat - Redirect to Error Page when ServletContextListener fails
Posted
by Vic
on Stack Overflow
See other posts from Stack Overflow
or by Vic
Published on 2010-05-27T17:15:44Z
Indexed on
2010/05/27
17:21 UTC
Read the original article
Hit count: 357
When Tomcat starts it calls my ServletContextListener to obtain a database connection, which I will later use in other servlets with getServletContext(). It is called in my web.xml as:
listener
(I removed the < > because they wouldn't display properly in this message.>
listener-class org.ppdc.database.DBCPoolingListener /listener-class
/listener>
If I cannot connect to the database when Tomcat starts up I get a 404 error, because Tomcat cannot start the application.
How can I redirect the user to a custom error page at this point? I tried the following in my web.xml (I have the < > brackets in the original):
(error-page)
(error-code404/error-code)
(location/file_not_found.html/location)
(/error-page)
Any ideas on how to redirect a user to one of my error pages when Tomcat tries to start the application?
Thanks Vic
© Stack Overflow or respective owner