Url模式,用于排除servlet过滤器调用的javax.faces.resource [英] Url pattern to exclude javax.faces.resource from being invoked by servlet filter

查看:121
本文介绍了Url模式,用于排除servlet过滤器调用的javax.faces.resource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 servlet过滤器来处理会话超时和身份验证。

I have created a servlet filter to handle session timeout and authentication.

@WebFilter(urlPatterns={"/acc/*"})
public class ResourceAuthorizationFilter implements Filter { ... }

我要过滤的页面有这样的模式: / acc / login-flow / acc / profiles-flow 。过滤器也被调用资源(css,js和images)。如何配置 urlPatterns 以排除过滤这些资源?

The pages that I want to filter have a pattern like this: /acc/login-flow, /acc/profiles-flow. The filter gets called also for resources(css, js and images). How can I configure the urlPatterns to exclude from filtering these resources?

EDIT1

以下是一些已过滤的网址:

EDIT1
Here are some urls that are filtered:

http://localhost:8081/acme-0.0.1/acc/login-flow
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/theme.css
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/jquery/jquery.js
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/primefaces.js
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/ajax.gif
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/login.png
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/header.png
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/images/ui-bg_flat_75_ffffff_40x100.png
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/images/default.png
http://localhost:8081/acme-0.0.1/acc/javax.faces.resource/images/ui-icons_888888_256x240.png

我在 webapp /下有一些自定义的css / js文件资源 fol但是,这些不是那里。

I have some custom css/js files under webapp/resources folder, but these ones are not from there.

acc 部分来自:

<servlet-mapping>
    <servlet-name>Spring MVC Servlet</servlet-name>
    <url-pattern>/acc/*</url-pattern>
</servlet-mapping>

EDIT2

这些代码示例来自使用JSF 2.0,PrimeFaces 3.4.1,Spring 3.0.5.RELEASE,Spring Security 3.0.3.RELEASE和Spring Web Flow 2.3.0.RELEASE实现的项目。

EDIT2
These code samples come from a project that is implemented with JSF 2.0, PrimeFaces 3.4.1, Spring 3.0.5.RELEASE, Spring Security 3.0.3.RELEASE and Spring Web Flow 2.3.0.RELEASE.

推荐答案

只需将资源移到 / acc 之外的其他文件夹即可。默认情况下它们应该在 / resources 文件夹中,以便您可以使用< h:outputScript> < h:outputStylesheet> < h:graphicImage> 正确的方式。

Just move resources to a different folder outside /acc. They're by default supposed to be in /resources folder anyway so that you can use <h:outputScript>, <h:outputStylesheet> and <h:graphicImage> the right way.

如果因某些原因无法解决问题,那么你真的需要检查 doFilter()实现中的请求URI 。有没有方法来排除URL模式中的子模式。

If you can't fix that for some reason, then you'd really need to check the request URI in the doFilter() implementation. There's namely no way to exclude sub-patterns in an URL pattern.

String path = request.getRequestURI().substring(request.getContextPath().length());

if (path.startsWith("/acc" + ResourceHandler.RESOURCE_IDENTIFIER)) {
    chain.doFilter(request, response);
} else {
    // ...
}






更新:根据您的问题更新,您使用Spring MVC有一些不明原因。它还处理所有JSF资源请求。你应该告诉它不要这样做。我不知道从头顶如何做到这一点,但它至少是< mvc:resources>


Update: as per your question update, you're using Spring MVC for some unclear reason. It's also processing all JSF resource requests. You should tell it to not do that. I can't tell from top of head how to do that, but it's at least something with <mvc:resources>.

这篇关于Url模式,用于排除servlet过滤器调用的javax.faces.resource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆