Creating a Filter

See Also

A filter is a piece of re-usable code that can transform the contents of HTTP requests, responses, and header information by modifying requests to and responses from a servlet.

You create a filter by implementing the javax.servlet.Filter interface and providing a public constructor taking no arguments. The IDE provides a wizard to help you create two types of filters:

Filters are declared using the filter element in the web module's deployment descriptor (web.xml) and are packaged in a WAR file along with the static content and servlets that make up a web module. A filter or collection of filters can be configured for invocation by defining the filter mapping elements in the deployment descriptor.

To create a Filter:

  1. Right-click the package where you want to put the filter and choose New and choose All Templates from the contextual menu.
  2. Expand JSP & Servlets, expand Filters, select the filter you want to create, and click Next.
  3. Follow the instructions in the General Filter Information page.
  4. Click Next to add the Filter configuration to deployment descriptor or click Finish to accept the default configuration. The IDE opens the source code in the Source Editor.
tip  If you want to keep your source separate from your class files, you must mount the directory above the package root and you must use the Options window to select WEB-INF/classes as the project's target directory for the External Compiler. Doing so ensures that code completion and compiling are supported by the IDE.

For more information about filters, see the Java Servlet Specification available at http://java.sun.com/products/servlet/download.html.

tip  To view the API documentation for servlet filters, choose View and choose Documentation Indices and choose Overview (Servlet API Documentation) from the main tool bar.
See Also

About Servlet Filters
Where to Put Web Module Files
Setting Filter Properties
Adding a Filter to the Deployment Descriptor


Legal Notices