Java Reference
In-Depth Information
HttpServletResponse res = (HttpServletResponse)response;
res.sendRedirect("html/downtimenotice.html");
}
}
public void init(FilterConfig config) throws ServletException {
startHour = Integer.parseInt(config.getInitParameter("starthour"));
endHour = Integer.parseInt(config.getInitParameter("endhour"));
}
}
In Listing 3-42 the doFilter implements the logic for time-based access to the eIn-
sure application. In this case only, the preprocessing of the incoming request is carried
out to check whether the scheduled office hour's window has expired for the day. If so,
the user is redirected to a downtime notice page. Otherwise, the next filters in the chain
(if any) are executed. Finally, the target servlet and page controllers will be executed.
Note that the official business hours are configurable. The filter is registered in web.xml , as
shown in Listing 3-43, along with various parameters and a URL mapping. In this case,
this filter intercepts all requests ending with .do and heading toward the front controller.
This solution is highly reusable and based on Java servlet standards. It can be used even
without Spring MVC support because the web container is responsible for managing the
filters.
Listing 3-43. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>timebasedaccess</filter-name>
<filter-class>
com.apress.insurance.web.filter.TimebasedAccessFilter
</filter-class>
<init-param>
<param-name>starthour</param-name>
<param-value>9</param-value>
</init-param>
<init-param>
Search WWH ::




Custom Search