0" encoding="ISO-8859-1"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
NoInvoker
coreservlets.NoInvokerServlet
NoInvoker
/servlet/*
...
Chapter 5 ?– Servlet and JSP Filters 210
5.2 Example: A Reporting Filter
Just to warm up, let??™s try a simple filter that merely prints a message to standard output
whenever the associated servlet or JSP page is invoked. To accomplish this task,
we implement the following capabilities.
1. A class that implements the Filter interface. This class is called
ReportFilter and is shown in Listing 5.2. The class provides empty
bodies for the init and destroy methods.
2. Filtering behavior in the doFilter method. Each time a servlet
or JSP page associated with this filter is invoked, the doFilter
method generates a printout that lists the requesting host and the
URL that was invoked. Because the getRequestURL method is in
HttpServletRequest, not ServletRequest, we cast the
ServletRequest object to HttpServletRequest.
3. A call to the doFilter method of the FilterChain.
Pages:
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260