Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Eclipse Web Tools Guide
Previous Page Home Next Page

Creating Filters

The filters wizard helps you to create Java™ servlet filters by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your Web application. The filters can run on Java EE-compliant Web servers.

To create a filter, complete the following steps:

  1. In the Java EE perspective, expand your dynamic project in the Project Explorer view.
  2. Right click on the Filter icon, and select New > Filter from the pop-up menu. The Create Filter wizard appears.
  3. Follow the project wizard prompts.

General Information

The Sun Microsystems Java Servlet 2.3 Specification states that a Servlet class must be public and not abstract. Therefore, you cannot change these modifiers. The only one available for change is the final modifier.
There is one obligatory interface that filter classes must implement: javax.servlet.Filter. This interface is provided by javax.servlet package and is used to represent the life-cycle of the filter. This interface has three methods: init, doFilter and destroy.
  • The init method is called by the servlet container only once, when it finishes instantiating the filter.
  • ThedoFilter method is where the filtering is performed and is called every time a user requests a resource, such as a servlet, to which the filter is mapped.
  • The destroy method is called by the servlet container to tell the filter that it will be taken out of service.
Although, that the javax.servlet.Filter interface is provided in the Interfaces field by default, you can add additional interfaces to implement by using the Add button.
Interface selection dialog
This dialog appears if you select to add an interface to your filter. As you type the name of the interface that you are adding, a list of available interfaces listed in the Matching items list box updates dynamically to display only the interfaces that match the pattern. Choose an interface to see the qualifier, and then click OK when finished.
Filter Mappings
For a filter to intercept a request to a servlet, you must:
  1. declare the filter with a <filter> element in the deployment descriptor
  2. map the filter to the servlet using the <filter-mapping> element.
Sometimes you want a filter to work on multiple servlets. You can do this by mapping a filter to a URL pattern so that any request that matches that URL pattern will be filtered. All this is made automatically if you use the Filter Mappings field.
Method stubs
Because each filter must implement the javax.servlet.Filter interface, the Inherited abstract methods option is always checked and cannot be changed.
Related concepts

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire