<< How can I automatically expire data from a database? | Home | Filtering characters from a Reader >>

How can I create a maintenance window for my web app?

Every so often, web applications need maintenance. Yes, even web applications. It's okay - no need to reach for your security blanket. The problem that's come up is: What's a good way to redirect requests during a maintenance window to an error page? As usual, there are multiple answers.

One answer is to use your servlet container! Install a "maintenance web application" with one page - and redirect all requests to that page - which says "Application under maintenance." In the maintenance window, change the application context so that it points to the maintenance application. When maintenance is done, the application context can be restored to point to the actual application.

Another answer is to have a servlet filter intercept requests, examining the application status and redirecting to an internal error page as necessary.  The code to do this can be found in MaintenanceFilter.java. The web application should be set up like this:
/index.jsp
/WEB-INF/web.xml
/WEB-INF/jsp/maintenance.jsp
/WEB-INF/classes/filters/MaintenanceFilter.class
Check the Javadoc in MaintenanceFilter for details on setting up the maintenance window. It's nothing special, but shows how it can be done.

Resources:



Add a comment Send a TrackBack