简体   繁体   English

过滤器在Struts2中不起作用

[英]Filters not working in Struts2

for some unknown reason I'm not being able to use filter on struts2. 由于某种未知的原因,我无法在struts2上使用过滤器。 I'm using apache tomcat and using filter to restrict user access ( I preffer rather than Interceptors). 我正在使用apache tomcat并使用过滤器来限制用户访问(我喜欢而不是拦截器)。 Is there any reason why my requests with /tela-paciente is not being filtering?? 有没有理由为什么我的/tela-paciente请求没有被过滤?

   <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>Paciente</filter-name>
        <filter-class>br.ufg.inf.sas.filtros.FiltroPaciente</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>Paciente</filter-name>
        <url-pattern>/tela-paciente</url-pattern>
    </filter-mapping>

Another thing to keep in mind is that in your example the mapping for /tela-paciente occurs after the mapping for /* (for the Struts2 filter), so all requests will be mapped to Struts2 and none will go to your security filter. 另外要记住的是,在您的示例中,/ tela-paciente的映射发生在/ *(对于Struts2过滤器)的映射之后,因此所有请求都将映射到Struts2,并且没有任何请求将转到您的安全过滤器。

Remember that the order of your filters matters. 请记住,过滤器的顺序很重要。 :) :)

@totaam: The StrutsPrepareAndExecuteFilter does not chain on to other filters unless: @totaam: StrutsPrepareAndExecuteFilter不链接到其他过滤器,除非:

  • The request URL is excluded from processing by the struts.action.excludePattern property 请求URL被struts.action.excludePattern属性从处理中排除
  • The request does not map to an action or a static resource 请求不会映射到操作或静态资源

Therefore, assuming his request does map to an action, his security filter will not be invoked if it is mapped after the Struts2 filter. 因此,假设他的请求映射到一个动作,如果它在Struts2过滤器之后被映射,则不会调用他的安全过滤器。

Have you tried setting the filter mapping to "/tela-paciente/*" ( <url-pattern>/tela-paciente/*</url-pattern> ) instead? 您是否尝试将过滤器映射设置为“/ tela-paciente / *”( <url-pattern>/tela-paciente/*</url-pattern> )?

Your question is a tomcat question, there is nothing in that particular mapping that relates to struts. 你的问题是一个tomcat问题,那个与struts相关的特定映射中没有任何内容。

The statement below by Steven Benitez is correct - my bad ("none will go to your security filter"). Steven Benitez的下面的陈述是正确的 - 我的坏(“没有人会去你的安全过滤器”)。

More general info on filters: they are processed unless one of the filters stops the processing by not calling down the filter chain (which may be the case here - this should be a rare thing though, to be used only when dealing with exceptions, when redirecting URLs or to prevent the page from loading). 关于过滤器的更一般信息:它们被处理,除非其中一个过滤器通过不调用过滤器链来停止处理(这可能就是这种情况 - 但这应该是一种罕见的事情,仅在处理异常时使用,当重定向URL或阻止页面加载)。 You can have as many filters as you like bound to overlapping sets of URLs. 您可以将多个过滤器绑定到重叠的URL集。

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

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