Creating a new filter class
The Filter wizard enables you to create Java filter classes for various J2EE filter types, such as authentication filters, encryption filters, and data compression filters.
To create a filter class, do the following:
- Open the Filter wizard. To do this:
The Create Filter wizard appears.
- Open the Web perspective and display the Project Explorer view.
- Expand the project in which you want to create the filter
- Expand the deployment descriptor icon
- Right click on the Filters icon.
- Select New > Filter from the pop-up menu.
- Type a name and description for the filter. Notice that the name that you type in the Name field is used to create a URL Mapping for the filter. Optionally add initialization parameters or an alternative URL mapping, and then select Next.
- Specify the folder where the filter class will be placed. (You should place the filter in the Java source folder) Also specify the package that the class will belong to (it is added into a default package if you do not specify one), and the class name of the filter.
- Specify a superclass for the filter class. A filter created by this wizard can have any class that has Object in its hierarchy as its superclass. Click Browse to choose from the available superclasses. When finished select Next.
- Select a modifier to specify whether your filter class is public, abstract, or final. (Classes cannot be both abstract and final.)
- The javax.servlet.Filter is provided as the default Interface. You do not have to implement the Filter interface if you subclass a class that implements Filter, or if you implement an interface which has Filter in its hierarchy.
You can also add additional interfaces to implement. Click Add to open the Interface Selection dialog. In this dialog, as you type the name of the interface that you are interested in adding in the Choose interfaces field, the list of available interfaces listed in the Matching types list box updates dynamically to display only the interfaces that match the pattern. Select an interface to see the Qualifier and click Add. Click OK when you are finished. The qualifier that you chose appears in the Interfaces dialog.
- Choose which method stub you want to create.
The Inherited abstract methods option adds stubs for inherited abstract methods, and that must be implemented (unless you intend to create an abstract class). Because the init(), destroy(), and doFilter() methods are all defined in the javax.servlet.Filter interface, stubs for these methods are automatically generated for each new filter class.
- Click Finish.
The filter that you created appears under the Filters icon.
Related concepts
The Web deployment descriptor editor