Writing Servlet 2.3 Filters
Pages: 1, 2, 3, 4
The web.xml to deploy this filter and define
initial parameters is shown in Listing 7.
Listing 7: The deployment descriptor that defines initial parameters for a filter. (web.xml)
<?xml version = "1.0" encoding = "ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<!-- Define the filters within the Web Application -->
<filter>
<filter-name>
Parsing Request Data
</filter-name>
<filter-class>
com.filters.RequestFilter
</filter-class>
<init-param>
<param-name>
User's Name
</param-name>
<param-value>
myname
</param-value>
</init-param>
<init-param>
<param-name>
User's Email
</param-name>
<param-value>
txtemail
</param-value>
</init-param>
</filter>
<!-- Map the filter to a Servlet or URL -->
<filter-mapping>
<filter-name>
Parsing Request Data
</filter-name>
<url-pattern>
/formprocessor
</url-pattern>
</filter-mapping>
<!-- Define the Servlets within the Web Application -->
<servlet>
<servlet-name>
No Form Submitted
</servlet-name>
<servlet-class>
com.servlets.NoElements
</servlet-class>
</servlet>
<servlet>
<servlet-name>
Empty Form Elements
</servlet-name>
<servlet-class>
com.servlets.InvalidEntries
</servlet-class>
</servlet>
<servlet>
<servlet-name>
Good Request
</servlet-name>
<servlet-class>
com.servlets.MyServlet
</servlet-class>
</servlet>
<!-- Define Servlet mappings to urls -->
<servlet-mapping>
<servlet-name>
No Form Submitted
</servlet-name>
<url-pattern>
/noform
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
Empty Form Elements
</servlet-name>
<url-pattern>
/emptyform
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
Good Request
</servlet-name>
<url-pattern>
/formprocessor
</url-pattern>
</servlet-mapping>
</web-app>
Summary
The Servlet 2.3 API specification provided important new
features. Application lifecycle events provide the developer
better control over the ServletContext object and
HttpSession objects. Filters provide a way to take
control logic out of servlets, placing it in more reusable pieces
of code.
Stephanie Fesler is a BEA Systems expert on implementing various Java 2EE API.
|
Related Articles: |
Return to ONJava.com.
-
Deploying the Filter
2008-05-27 23:47:01 Jamith [View]
-
Source code
2007-10-16 01:52:11 JavaGalaxy.com [View]
-
Necessary note
2003-11-19 00:46:27 anonymous2 [View]
-
UrlRewriteFilter
2003-09-03 22:54:58 anonymous2 [View]
-
Implementing Filter Servlet for WebServices in WebLogic
2003-06-20 21:00:17 anonymous2 [View]
-
anonym
2002-10-30 10:58:39 anonymous2 [View]
-
How do i get the name/url of the resource being requested in the doFilter method of the filter.
2002-10-28 03:29:28 anonymous2 [View]
-
I run the RequestFilter example, but error show on the screen,Why?
2002-09-05 19:55:57 founder_chen [View]
-
comment
2002-03-12 00:01:56 miks [View]
-
Stéphanie Fesler articles
2001-08-08 01:58:25 jkinder [View]