9.6. Example: An Access Time Filter

The LogFilter of Section 9.4 prints an entry in the log file every time the associated servlet or JSP page is accessed. Suppose you want to modify it so that it only notes accesses that occur at unusual times. Since “unusual” is situation dependent, the servlet should provide default values for the abnormal time ranges and let deployers override these values by supplying initialization parameters. To implement this functionality, the filter has the following capabilities.

  1. A class that implements the Filter interface. This class is called LateAccessFilter and is shown in Listing 9.9. The init method of this class reads the startTime and endTime initialization parameters. It attempts to parse these values as ...

Get More Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.