File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Filtering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filtering" Watch "Filtering" New topic


Anuradha Sridharan

Joined: Nov 03, 2003
Posts: 3
Hi all,
Could someone explain to me what is the concept of filtering in Servlets? Any pointers to references related to this topic are also welcome.
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
A filter can be applied to one or more servlet/JSP files. A filter is an
object that can transform a request or modify a response. It can
preprocess a request BEFORE it reaches a servlet and it can preprocess a response after it leaves the servlet.
  • A client sends a request
  • The filter intercepts the client request
  • The filter examines and can modify the request header and request data by using its own custom request to wrap araond the intercepted request object
  • the filter propagates the request to the servlet
  • the servlet generates a response a flushes it.
  • the filter intercepts the response
  • the filter can modify the headers and data by using its own custom response
  • Once completed, the filter sends the newly filtered response to the client

  • A filter must implement the javax.servlet.Filter interface.
    Let's say we create a filter.

    then in your web.xml file

    after this you can either filter specific servlets or URL patterns
    specific servlet

    Url patterns

    Hope this helps you

    SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
    Mathias Nilsson
    Ranch Hand

    Joined: Oct 13, 2003
    Posts: 107
    Check this link out
    [ November 04, 2003: Message edited by: Mathias Nilsson ]
    Mathias Nilsson
    Ranch Hand

    Joined: Oct 13, 2003
    Posts: 107
    the mapping for jsp files should be

    And not

    // Mathias
    I agree. Here's the link:
    subject: Filtering
    It's not a secret anymore!