Simplest Possible Filter

Introduction

This is the simplest possible servlet filter. I demonstrates how the filter can take action before the target is called and after the target is called.

Steps

  1. Create SimpleFilter.java
  2. Create Target.jsp
  3. Declare filter in deployment descriptor
  4. Map SimpleFilter to Target.jsp in deployment descriptor

Final Code

  • Source: Target.jsp
  • Source: smartsoft/tutorial/filters/SimpleFilter.java
  • Source: /WEB-INF/web.xml
  • Run It

  • Target.jsp