我正在使用带有 Google App Engine 插件的 Eclipse IDE 和 Guice。在开发服务器上运行时,我在 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/*
应该适用于两者,对吗?
...我怀疑它与文件本身有关,因为我似乎也无法过滤 "*.html"
。
编辑:已解决。叹息...我在 GAE/J 文档中发现了这个花絮:
“注意:即使路径与过滤器映射模式匹配,也不会在静态资源上调用过滤器。静态文件直接提供给浏览器。”
最佳答案
我在 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 中却做不到。
关于google-app-engine - 奇怪的 Java Servlet 过滤器映射行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9469032/