aspose file tools
The moose likes Servlets and the fly likes why we have filters? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "why we have filters?" Watch "why we have filters?" New topic
Author

why we have filters?

krishnama raju
Greenhorn

Joined: Dec 24, 2009
Posts: 7
i didn't understand , why we have filters?

is there any special purpose for filters. all examples i have seen is just simple ones. i didn't get any knowledge from that.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12266
    
    1
One basic principle of modern computer architecture is separation of concerns.

By creating filters for particular common processes we make it easier to put together systems with parts that are known to work. You dont have to reinvent the wheel for every application.

Bill


Java Resources at www.wbrogden.com
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56166
    
  13

Some example of filters that I use:
  • Check that there is a logged in user; redirect to login if not.
  • Add no-cache headers to the response.
  • Ensure that a Hibernate session is active.

  • That way, each and every servlet or JSP doesn't need to be concerned with these things that have to happen in every request.

    [Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
    Ramakrishna Gutha
    Greenhorn

    Joined: Jan 18, 2010
    Posts: 16
    As bill said it is separation of particular concern.

    To demonstrate it properly, we have used a Tuckey's UrlRewrite filter. Our requirement is show the URL's in SEO friendy manner like www.nissan.com/Acura/MDX instead of www.nissan.com?make=Acura&model=MDX.

    The job of the filter is to convert the SEO friendly url to Server understandable URL. This made our pages get ranked more by Search Engines and improved the readability.

    Thanks
    GRK
    David Newton
    Author
    Rancher

    Joined: Sep 29, 2008
    Posts: 12617

    Compression is another common use for filters, i.e. sending back gzipped data to the client. There are a *lot* of reasonable uses for filters.
    Vijay Kumar
    Ranch Hand

    Joined: Jul 24, 2003
    Posts: 260

    It is one of the robust feature. You can intercepts requests and responses.

    Please see given URL

    Essentials of Filter.

    Regards,
    Vijay
     
    jQuery in Action, 2nd edition
     
    subject: why we have filters?
     
    Similar Threads
    load-on-startup for filter
    Filters in exam ????
    Need help in Maintaining Seesion.
    Filter doubts
    Servlet auto redirect to another page