tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <funk...@joedog.org>
Subject Re: ServletContextListener: how to suspend web app on error
Date Fri, 09 Jan 2004 12:07:19 GMT
A simple generic way is to use a filter which executes on all requests.

If the ServletContextListener has an error - it can set a variable in the 
application context.

Then the filter can check for the existence of that variables. Then forward 
to an "error page".

For example ...
doFilter( ... ) {
    if (null!=servletContext.getAttribute("startupError")) {
        servletContext.getRequestDispatcher("/WEB-INF/error.jsp")
           .forward(request, response);
    } else {
        chain.doFilter(...);
    }
}

-Tim

Justin Ruthenbeck wrote:
> 
> Seems like a simple question, can't seem to find the answer...
> 
> If an error occurs in the #contextInitialized() method of an object that 
> implements ServletContextListener, how can I suspend the web application 
> so that it is unavailable for use by clients?
> 
> Specifically, I have a ServletContextListener that needs to be run at 
> application startup.  If any one of many errors occur, I want to notify 
> the appropriate people (this I can do) and make the entire webapp 
> unavailable (this I can't figure out).
> 
> Any help is appreciated.  I have a feeling this is obvious and I'm just 
> missing something.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message