Chapter 7 - Filters

This chapter explains how to use filters to pre-process a request and to post-process a response.
  1. The HelloWorldFilter explained in listing 7.1 is configured in the web.xml as follows:
       <filter>
          <filter-name>HelloWorld</filter-name>
          <filter-class>chapter07.HelloWorldFilter</filter-class>
       </filter>
       
       <filter-mapping>
          <filter-name>HelloWorld</filter-name>
          <url-pattern>/filter/*</url-pattern>
       </filter-mapping>
    
    Any request that matches the pattern /filter/* - for example, /chapter07/filter/hello - invokes the HelloWorldFilter.
     
  2. For experimenting with filter chaining, we have configured multiple filters as explained in section 7.3.3. You should try out all the URLs mentioned in the section and see what filters are invoked.
     
  3. The TextToHTMLFilter explained in section 7.4 is configured as follows:
       <filter>
          <filter-name>TextToHTML</filter-name>
          <filter-class>chapter07.TextToHTMLFilter</filter-class>
       </filter>
    
       <filter-mapping>
          <filter-name>TextToHTML</filter-name>
          <url-pattern>*.txt</url-pattern>
       </filter-mapping>
      
      
    Therefore, all the text files are sent with a background image. You can view a sample text file at /chapter07/ReportJanFeb.txt