blob: fcb8aa0b4aed13fb31c03633f5842873b6201440 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="copyright" content="Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: IBM Corporation - initial API and implementation" />
<meta name="DC.rights.owner" content="(C) Copyright 2000, 2008" />
<meta content="public" name="security" />
<meta content="index,follow" name="Robots" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta content="task" name="DC.Type" />
<meta name="DC.Title" content="Creating Filters" />
<meta name="abstract" content="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." />
<meta name="description" content="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." />
<meta content="servlets, creating" name="DC.subject" />
<meta content="servlets, creating" name="keywords" />
<meta scheme="URI" name="DC.Relation" content="../topics/cwfiltbn.html" />
<meta content="XHTML" name="DC.Format" />
<meta content="twfltwiz" name="DC.Identifier" />
<meta content="en-us" name="DC.Language" />
<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
<title>Creating Filters</title>
</head>
<body id="twfltwiz"><a name="twfltwiz"><!-- --></a>
<h1 class="topictitle1">Creating Filters</h1>
<div><p>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.</p>
<div class="section"> <p>To create a filter, complete the following steps: </p>
</div>
<ol>
<li class="stepexpand"><span>In the Java EE perspective, expand your <a href="ccwebprj.html" title="">dynamic project</a> in the Project Explorer view.</span>
</li>
<li class="stepexpand"><span>Right click on the <strong>Filter</strong> icon, and select <span class="menucascade">
<span class="uicontrol">New</span> &gt; <span class="uicontrol">Filter</span></span> from
the pop-up menu.</span> The <span class="uicontrol">Create Filter</span> wizard
appears.</li>
<li class="stepexpand"><span>Follow the project wizard prompts.</span></li>
</ol>
<div class="section"><p><strong>General Information</strong></p>
<dl>
<dt class="dlterm">Modifiers</dt>
<dd>The <cite>Sun Microsystems Java Servlet 2.3 Specification</cite> states
that a Servlet class must be <strong>public</strong> and not <strong>abstract</strong>. Therefore,
you cannot change these modifiers. The only one available for change is the <strong>final</strong> modifier.</dd>
<dt class="dlterm">Interfaces</dt>
<dd>There is one obligatory interface that filter classes must implement: <strong>javax.servlet.Filter</strong>.
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. <ul>
<li>The <strong>init</strong> method is called by the servlet container only once, when
it finishes instantiating the filter.</li>
<li>The<strong>doFilter</strong> 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.</li>
<li>The <strong>destroy</strong> method is called by the servlet container to tell the
filter that it will be taken out of service.</li>
</ul>
Although, that the javax.servlet.Filter interface is provided in the <strong>Interfaces</strong> field
by default, you can add additional interfaces to implement by using the <strong>Add</strong> button.</dd>
<dt class="dlterm">Interface selection dialog</dt>
<dd>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 <strong>Matching items</strong> list box updates dynamically
to display only the interfaces that match the pattern. Choose an interface
to see the qualifier, and then click <strong>OK</strong> when finished.</dd>
<dt class="dlterm">Filter Mappings</dt>
<dd>For a filter to intercept a request to a servlet, you must: <ol>
<li>declare the filter with a <strong>&lt;filter&gt;</strong> element in the deployment
descriptor</li>
<li>map the filter to the servlet using the <strong>&lt;filter-mapping&gt;</strong>
element.</li>
</ol>
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 <strong>Filter Mappings</strong> field.</dd>
<dt class="dlterm">Method stubs</dt>
<dd>Because each filter must implement the javax.servlet.Filter interface,
the <strong>Inherited abstract methods</strong> option is always checked and cannot
be changed.</dd>
</dl>
</div>
</div>
<div><div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="../topics/cwfiltbn.html">Filters</a></div>
</div>
</div>
</body>
</html>