| <?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, 2006 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, 2006" /> |
| <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 content="filters, creating" name="DC.subject" /> |
| <meta content="filters, creating" name="keywords" /> |
| <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 filter wizard helps you 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> > <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> |
| |
| <p><dt class="dlterm">Modifiers</dt></p> |
| |
| <dd>The <cite>Sun Microsystems Java Servlet Specification</cite> states that a |
| Servlet class must be <b>public</b> and not <b>abstract</b>. Therefore, |
| you cannot change these modifiers. The only one available for change is |
| the <b>final</b> modifier. </dd> |
| |
| |
| <p><dt class="dlterm">Interfaces</dt></p> |
| |
| <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> |
| You can add additional interfaces to implement by using the <strong>Add</strong> |
| button.</dd> |
| |
| |
| <p> |
| <dt class="dlterm">Interfaces dialog</dt> |
| </p> |
| |
| <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 <b>Matching items</b> list box |
| updates dynamically to display only the interfaces that match the |
| pattern. Choose an interface to see the qualifier, and then |
| click <b>OK</b> when finished.</dd> |
| |
| |
| <p><dt class="dlterm">Filter Mappings</dt></p> |
| |
| <dd>For a filter to intercept a request to a servlet, you must: |
| <ol> |
| <li>declare the filter with a <b><filter></b> element in |
| the deployment descriptor</li> |
| <li>map the filter to the servlet using the <b><filter-mapping></b> |
| 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 <b>Filter Mappings</b> field.</dd> |
| |
| <p><dt class="dlterm">Method stubs</dt></p> |
| <dd>Because each filter must implement the javax.servlet.Filter |
| interface, the <b>Inherited abstract methods</b> option is always |
| checked and cannot be changed.</dd> |
| |
| </dl> |
| </div> |
| |
| </div> |
| </body> |
| </html> |
| |