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:

  1. Open the Filter wizard. To do this:

    1. Open the Web perspective and display the Project Explorer view.

    2. Expand the project in which you want to create the filter

    3. Expand the deployment descriptor icon

    4. Right click on the Filters icon.

    5. Select New > Filter from the pop-up menu.
    The Create Filter wizard appears.

  2. 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.

  3. 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.

  4. 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.

  5. Select a modifier to specify whether your filter class is public, abstract, or final. (Classes cannot be both abstract and final.)

  6. 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.

  7. 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.

  8. Click Finish.

The filter that you created appears under the Filters icon.

 

Related concepts

The Web deployment descriptor editor