9.3. Accessing the Servlet Context from Filters

The ReportFilter of the previous section prints a report on the standard output whenever the designated servlet or JSP page is invoked. A report on the standard output is fine during development—when you run a server on your desktop you typically have a window that displays the standard output. During deployment, however, you are unlikely to have access to this window. So, a natural enhancement is to write the reports into the servlet log file instead of to the standard output.

The servlet API provides two log methods: one that takes a simple String and another that takes a String and a Throwable. These two methods are available from either the GenericServlet or ServletContext classes. Check your ...

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.