【问题标题】:Strange Java Servlet Filter-Mapping Behaviour奇怪的 Java Servlet 过滤器映射行为
【发布时间】:2023-03-17 13:16:01
【问题描述】:

我正在使用带有 Google App Engine 插件和 Guice 的 Eclipse IDE。在开发服务器上运行,我在 web.xml 和 guice MyServletModule extends ServletModule 中尝试了这两种方法:

<url-pattern>/user/*</url-pattern>

filter("/user/*").through(LoginFilter.class); 

两者似乎都适用

http://www.domain.com/user/

但是......似乎都不适用于:

http://www.domain.com/user/myaccount.html

知道为什么吗?根据文档,/user/* 应该适用于两者,对吧?

...我怀疑它与 itaself 文件有关,因为我似乎也无法过滤 "*.html"

编辑已解决。叹息......我在 GAE/J 文档中发现了这个花絮: "Note: Filters are not invoked on static assets, even if the path matches a filter-mapping pattern. Static files are served directly to the browser."

【问题讨论】:

    标签: google-app-engine servlet-filters web.xml


    【解决方案1】:

    我在 GAE/J 文档中发现了这个花絮:

    Note: Filters are not invoked on static assets, even if the path matches a filter-mapping pattern. Static files are served directly to the browser.
    

    尽管所有 Java Servlet 文档都说您可以做到,但在 GAE/J 中却无法做到。

    【讨论】:

      【解决方案2】:

      我发现这种模式有效:

      <security-constraint>
          <web-resource-collection>
              <url-pattern>/myFile.html</url-pattern>
          </web-resource-collection>
          <auth-constraint>
              <role-name>*</role-name>
          </auth-constraint>
      </security-constraint>
      

      .. 所以如果你指定一个文件,它可能会被过滤!

      【讨论】:

      • 谢谢。是的,这些本地 GAE 约束确实有效,但我需要添加对存储的会话数据的自定义检查,我在过滤器中执行此操作,而约束没有给我。我只是把我的静态 *.html 变成了 *.jsp。
      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 2011-04-10
      • 2014-04-19
      • 1970-01-01
      • 2013-10-05
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多