从某些网址中排除过滤器 [英] Exclude filter from certain url's
问题描述
我在 web.xml 中使用过滤器来检查用户是否登录:
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>
这就像一个魅力,直到我有一个我想从这个过滤器中排除的样式表或图像.我知道一种方法是将所有受保护的内容放在 /private
或类似内容中,然后将 url-pattern 设置为:<url-pattern>/private/*</url-模式>
.这样做的缺点是我的 URL 现在看起来像:http://www.mycompany.com/private/mypage
而不是 http://www.mycompany.com/mypage
>.这个问题有没有另一种解决方案,让我保留我的漂亮网址?
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 /private
or 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?
推荐答案
一个解决方案应该是 SpringSecurity(以前是 Acegi Security)方法:让你的 url-pattern 包含所有内容并排除过滤器主体中不需要的模式.
One solution should be the SpringSecurity (was Acegi Security) approach: make your url-pattern includes everything and exclude undesidered patterns in your filter body.
这篇关于从某些网址中排除过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!