424 CHAPTER 10 INTRODUCTION TO FILTERING Now (Web design software)

424 CHAPTER 10 INTRODUCTION TO FILTERING Now to check that the filter has actually worked for this simple static page, let s read the application log file found lurking in the Tomcat logs directory. The log file will be named after the current date, something like localhost_log.2005-08-04.txt. Inside, you should find the two log entries written by the filter, one entry created by the log() method prior to the doFilter() method call, and one created by the log() method after the doFilter() method call. On our test system, here are the two log entries: 2005-07-27 10:09:58 StandardContext[/filters1]in SimpleFilter 2005-07-27 10:09:59 StandardContext[/filters1]Getting out of SimpleFilter Experimentation with Filter Chaining Now you ll create a second filter called SimpleFilter2 (see Listing 10-4). Like SimpleFilter, it just logs each request in the log file. Chaining these filters together will give us some insight into the action of filter chaining under Tomcat 5. Listing 10-4. SimpleFilter2.java package com.apress.projsp.filters; import java.io.IOException; import javax.servlet.*; public final class SimpleFilter2 implements Filter { private FilterConfig filterConfig = null; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { filterConfig.getServletContext().log(”in SimpleFilter2″); chain.doFilter(request, response); filterConfig.getServletContext().log(”leaving SimpleFilter2″); } public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; } public void destroy() {} } Additions to web.xml You can now add SimpleFilter2 to the chain. Listing 10-5 shows the updated web.xml, with a new entry for SimpleFilter2, and an updated sequence of elements. Ensure the ordering of entries is followed exactly.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Leave a Reply