Exclude filter from certain url's

Posted by Mads Mobæk on Stack Overflow See other posts from Stack Overflow or by Mads Mobæk
Published on 2009-11-29T23:42:35Z Indexed on 2010/04/15 15:53 UTC
Read the original article Hit count: 496

Filed under:
|

I'm using a filter in web.xml to check if a user is logged in or not:

<filter>
    <filter-name>LoginFilter</filter-name>
    <filter-class>com.mycompany.LoginFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>LoginFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And this works like a charm until I have a stylesheet or image I want to exclude from this filter. I know one approach is to put everything that's protected inside /privateor similar, and then set the url-pattern to: <url-pattern>/private/*</url-pattern>. The downside to this is my URLs now looking like: http://www.mycompany.com/private/mypage instead of http://www.mycompany.com/mypage. Is there another solution to this problem, that let me keep my pretty-urls?

© Stack Overflow or respective owner

Related posts about java

Related posts about servlet-filter