Web hosting provider - CHAPTER 11 ADVANCED FILTERING TECHNIQUES 447 No

CHAPTER 11 ADVANCED FILTERING TECHNIQUES 447 No Figure 11-7. When a request is made outside the allowable hours, the filter denies access to the requested resource. Listing 11-9 shows the code for StopGamesFilter. The filter is designed to allow you to make the range of allowable hours a configurable parameter, to make the filter flexible enough for use in different environments. It also gives you a chance to see how to access and work with initial parameters in filters. Listing 11-9. StopGamesFilter.java package com.apress.projsp; import java.io.*; import javax.servlet.*; import java.util.Calendar; public final class StopGamesFilter implements Filter { private FilterConfig filterConfig = null; private int starthour = 0; private int stophour = 24; // default is to allow all the time public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Calendar myCal = Calendar.getInstance(); int curhour = myCal.get(Calendar.HOUR_OF_DAY); filterConfig.getServletContext().log( “in StopGamesFilter cur:” + curhour + “, start: ” + starthour + “, end: ” + stophour); if ((curhour >= stophour) || (curhour < starthour)) { PrintWriter out = response.getWriter();
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply