Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filtering

 
Anuradha Sridharan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
Anu.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Mathias Nilsson
    Ranch Hand
    Posts: 107
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Check this link out
    http://developer.java.sun.com/developer/technicalArticles/Servlets/servletapi2.3/
    [ November 04, 2003: Message edited by: Mathias Nilsson ]
     
    Mathias Nilsson
    Ranch Hand
    Posts: 107
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    http://www.rollerweblogger.org/page/roller/20030606
    the mapping for jsp files should be

    And not

    // Mathias
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic