The second
argument is a ServletResponse; it is mostly ignored in simple filters.
The final argument is a FilterChain; it is used to invoke the
servlet, JSP page, or the next filter in the chain as described in the next
step.
3. Call the doFilter method of the FilterChain object. The
doFilter method of the Filter interface takes a FilterChain
object as one of its arguments. When you call the doFilter method
of that object, the next associated filter is invoked. If no other filter is
associated with the servlet or JSP page, then the servlet or page itself
is invoked.
4. Register the filter with the appropriate servlets and JSP pages.
Use the filter and filter-mapping elements in the deployment
descriptor (web.xml).
5. Disable the invoker servlet. Prevent users from bypassing filter settings
by using default servlet URLs.
Details follow.
5.1 Creating Basic Filters 205
Create a Class That Implements
the Filter Interface
All filters must implement javax.servlet.Filter. This interface comprises
three methods: doFilter, init, and destroy.
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException, IOException
The doFilter method is executed each time a filter is invoked (i.e., once for
each request for a servlet or JSP page with which the filter is associated). It is
this method that contains the bulk of the filtering logic.
The first argument is the ServletRequest associated with the incoming
request.
Pages:
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253