简体   繁体   English

使用漂亮的脸与web过滤器

[英]using pretty faces with web filters

Using Tomcat 7 --- Primefaces 3.4.1 --- javax faces 2.1.17 --- prettyfaces-jsf2 3.3.3 使用Tomcat 7 --- Primefaces 3.4.1 --- javax面2.1.17 --- prettyfaces-jsf2 3.3.3

I configured pretty faces on my project correctly but my web filters are not working with new urls which are written by pretty faces. 我正确地在我的项目上配置了漂亮的面孔,但是我的网页过滤器没有使用由漂亮的面孔编写的新网址。

Here is an example pretty-config.xml 这是一个示例pretty-config.xml

<url-mapping id="home">
    <pattern value="/home"/>
    <view-id value="/secure/homepage.xhtml"/>
</url-mapping>

<url-mapping id="register">
    <pattern value="/register"/>
    <view-id value="/public/register.xhtml"/>
</url-mapping>

<url-mapping id="welcome">
    <pattern value="/"/>
    <view-id value="/public/welcome.xhtml"/>
</url-mapping>

<url-mapping id="profile">
    <pattern value="/profile/#{userId}"/>
    <view-id value="/profile.xhtml"/>
</url-mapping>

login(welcome) and register pages are in "public" folder, and their web filter is defined with annotation : @WebFilter("/public/*") 登录(欢迎)和注册页面位于“公共”文件夹中,其Web过滤器使用注释定义: @WebFilter(“/ public / *”)

for my home page in "secure" folder (exactly there will be more pages in the folder), i defined a web filter also and its annotation : @WebFilter("/secure/*) 对于我在“安全”文件夹中的主页(确切地说文件夹中会有更多页面),我还定义了一个Web过滤器及其注释: @WebFilter(“/ secure / *)

pretty urls are working fine, but these filters are only working when i write the original urls. 漂亮的网址工作正常, 但这些过滤器只在我写原始网址时才有效。

1) How can i repair my webfilters ? 1)我如何修复我的网络过滤器?

2) I also want to block user for entering original url. 2)我还想阻止用户输入原始网址。 I know that pretty faces is hiding original urls fully but is there a way to do it ? 我知道漂亮的面孔完全隐藏了原始网址但是有办法吗?

-- SOLVED -- thanks for BalusC - 已解决 - 感谢BalusC

if you defined your filters with annotations, you can configure dispatcher settings like 如果您使用注释定义了过滤器,则可以配置调度程序设置,例如

@WebFilter(urlPatterns = "/public/*", dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD} ) @WebFilter(urlPatterns =“/ public / *”, dispatcherTypes = {DispatcherType.REQUEST,DispatcherType.FORWARD}

PrettyFaces uses like many URL-rewriting solutions RequestDispatcher#forward() to forward the request to the desired target resource. PrettyFaces使用许多URL重写解决方案RequestDispatcher#forward()将请求转发到所需的目标资源。

Servlet filters, when mapped without any <dispatcher> , listens by default on "initial" requests only, not on forwarded, included, nor error'ed requests. 当没有任何<dispatcher>映射时,Servlet过滤器默认只在“初始”请求上进行侦听,而不是在转发,包含或错误请求上进行侦听。

So, when you map another servlet filter in web.xml after the PrettyFaces one, then it would by default not be triggered, unless you explicitly set a <dispatcher> on FORWARD next to the default of REQUEST (you should keep this one for the case PrettyFaces actually doesn't need to perform a forward). 因此,当您在PrettyFaces 之后web.xml映射另一个servlet过滤器时,默认情况下它不会被触发,除非您在REQUEST的默认值旁边显式设置FORWARD上的<dispatcher> (你应该保留这个)案例PrettyFaces实际上不需要执行转发)。

<filter-mapping>
    ...
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

Or, for the case you're using @WebFilter on your filters, use the dispatcherTypes attribute: 或者,对于在过滤器上使用@WebFilter的情况,请使用dispatcherTypes属性:

@WebFilter(..., dispatcherTypes = { REQUEST, FORWARD })

Alternatively, if the filter in question doesn't change the request/response target in any way, eg setting the charset, compressing using Gzip, listening on exceptions, etc, then you can also just put it before the PrettyFaces one. 或者,如果有问题的过滤器没有以任何方式更改请求/响应目标,例如设置字符集,使用Gzip压缩,监听异常等,那么您也可以将它放在PrettyFaces 之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM