blob: fcb8aa0b4aed13fb31c03633f5842873b6201440 [file] [log] [blame]
kprice96ee3b52008-05-15 00:05:07 +00001<?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">
kpricead5e1e92008-04-24 00:02:23 +00002<html lang="en-us" xml:lang="en-us">
3<head>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
kprice96ee3b52008-05-15 00:05:07 +00005<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" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2008" />
kpricead5e1e92008-04-24 00:02:23 +00007<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
kprice96ee3b52008-05-15 00:05:07 +00009<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))' />
kpricead5e1e92008-04-24 00:02:23 +000010<meta content="task" name="DC.Type" />
11<meta name="DC.Title" content="Creating Filters" />
kprice96ee3b52008-05-15 00:05:07 +000012<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." />
13<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." />
14<meta content="servlets, creating" name="DC.subject" />
15<meta content="servlets, creating" name="keywords" />
16<meta scheme="URI" name="DC.Relation" content="../topics/cwfiltbn.html" />
kpricead5e1e92008-04-24 00:02:23 +000017<meta content="XHTML" name="DC.Format" />
18<meta content="twfltwiz" name="DC.Identifier" />
19<meta content="en-us" name="DC.Language" />
kprice96ee3b52008-05-15 00:05:07 +000020<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
kpricead5e1e92008-04-24 00:02:23 +000021<title>Creating Filters</title>
22</head>
kprice96ee3b52008-05-15 00:05:07 +000023<body id="twfltwiz"><a name="twfltwiz"><!-- --></a>
kpricead5e1e92008-04-24 00:02:23 +000024
25
26<h1 class="topictitle1">Creating Filters</h1>
27
kpricead5e1e92008-04-24 00:02:23 +000028
kpricead5e1e92008-04-24 00:02:23 +000029
kprice96ee3b52008-05-15 00:05:07 +000030<div><p>The filters wizard helps you to create Java™ servlet filters by walking you through
31the creation process and by providing you with output files that you can use
32or that you can modify for use with your Web application. The filters can
33run on Java EE-compliant Web servers.</p>
kpricead5e1e92008-04-24 00:02:23 +000034
kprice96ee3b52008-05-15 00:05:07 +000035<div class="section"> <p>To create a filter, complete the following steps: </p>
36</div>
37
38<ol>
39<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>
40</li>
41
42<li class="stepexpand"><span>Right click on the <strong>Filter</strong> icon, and select <span class="menucascade">
43<span class="uicontrol">New</span> &gt; <span class="uicontrol">Filter</span></span> from
44the pop-up menu.</span> The <span class="uicontrol">Create Filter</span> wizard
45appears.</li>
46
47<li class="stepexpand"><span>Follow the project wizard prompts.</span></li>
48
49</ol>
50
51<div class="section"><p><strong>General Information</strong></p>
kpricead5e1e92008-04-24 00:02:23 +000052<dl>
kprice96ee3b52008-05-15 00:05:07 +000053<dt class="dlterm">Modifiers</dt>
kpricead5e1e92008-04-24 00:02:23 +000054
kprice96ee3b52008-05-15 00:05:07 +000055<dd>The <cite>Sun Microsystems Java Servlet 2.3 Specification</cite> states
56that a Servlet class must be <strong>public</strong> and not <strong>abstract</strong>. Therefore,
57you cannot change these modifiers. The only one available for change is the <strong>final</strong> modifier.</dd>
kpricead5e1e92008-04-24 00:02:23 +000058
59
kprice96ee3b52008-05-15 00:05:07 +000060<dt class="dlterm">Interfaces</dt>
kpricead5e1e92008-04-24 00:02:23 +000061
kprice96ee3b52008-05-15 00:05:07 +000062<dd>There is one obligatory interface that filter classes must implement: <strong>javax.servlet.Filter</strong>.
63This interface is provided by javax.servlet package and is used to represent
64the life-cycle of the filter. This interface has three methods: init, doFilter
65and destroy. <ul>
66<li>The <strong>init</strong> method is called by the servlet container only once, when
67it finishes instantiating the filter.</li>
68
69<li>The<strong>doFilter</strong> method is where the filtering is performed and is called
70every time a user requests a resource, such as a servlet, to which the filter
71is mapped.</li>
72
73<li>The <strong>destroy</strong> method is called by the servlet container to tell the
74filter that it will be taken out of service.</li>
75
76</ul>
77 Although, that the javax.servlet.Filter interface is provided in the <strong>Interfaces</strong> field
78by default, you can add additional interfaces to implement by using the <strong>Add</strong> button.</dd>
kpricead5e1e92008-04-24 00:02:23 +000079
80
kprice96ee3b52008-05-15 00:05:07 +000081<dt class="dlterm">Interface selection dialog</dt>
kpricead5e1e92008-04-24 00:02:23 +000082
kprice96ee3b52008-05-15 00:05:07 +000083<dd>This dialog appears if you select to add an interface to your filter.
84As you type the name of the interface that you are adding, a list of available
85interfaces listed in the <strong>Matching items</strong> list box updates dynamically
86to display only the interfaces that match the pattern. Choose an interface
87to see the qualifier, and then click <strong>OK</strong> when finished.</dd>
kpricead5e1e92008-04-24 00:02:23 +000088
89
kprice96ee3b52008-05-15 00:05:07 +000090<dt class="dlterm">Filter Mappings</dt>
kpricead5e1e92008-04-24 00:02:23 +000091
kprice96ee3b52008-05-15 00:05:07 +000092<dd>For a filter to intercept a request to a servlet, you must: <ol>
93<li>declare the filter with a <strong>&lt;filter&gt;</strong> element in the deployment
94descriptor</li>
kpricead5e1e92008-04-24 00:02:23 +000095
kprice96ee3b52008-05-15 00:05:07 +000096<li>map the filter to the servlet using the <strong>&lt;filter-mapping&gt;</strong>
97element.</li>
98
99</ol>
100 Sometimes you want a filter to work on multiple servlets. You can do
101this by mapping a filter to a URL pattern so that any request that matches
102that URL pattern will be filtered. All this is made automatically if you use
103the <strong>Filter Mappings</strong> field.</dd>
104
105
106<dt class="dlterm">Method stubs</dt>
107
108<dd>Because each filter must implement the javax.servlet.Filter interface,
109the <strong>Inherited abstract methods</strong> option is always checked and cannot
110be changed.</dd>
kpricead5e1e92008-04-24 00:02:23 +0000111
112</dl>
113</div>
114
115</div>
kpricead5e1e92008-04-24 00:02:23 +0000116
kprice96ee3b52008-05-15 00:05:07 +0000117<div><div class="relconcepts"><strong>Related concepts</strong><br />
118<div><a href="../topics/cwfiltbn.html">Filters</a></div>
119</div>
120</div>
121
122</body>
123</html>