首先,我正在使用Google AppEngine和Guice,但我怀疑我的问题与这些无关。
当用户连接到我的(GWT)webapp时,URL是直接的html页面。例如,在开发模式中,它是:http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997
。现在,我按以下方式设置web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>PuzzleBazar</display-name>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Puzzlebazar.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
This Guice listener hijacks all further filters and servlets. Extra
filters and servlets have to be configured in your
ServletModule#configureServlets() by calling
serve(String).with(Class<? extends HttpServlet>) and
filter(String).through(Class<? extends Filter)
-->
<listener>
<listener-class>com.puzzlebazar.server.guice.MyGuiceServletContextListener
</listener-class>
</listener>
</web-app>
我的appengine-web.xml
是:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>puzzlebazaar</application>
<version>1</version>
<sessions-enabled>true</sessions-enabled>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
由于我正在使用Guice,我必须在ServletModule中配置额外的过滤器,我这样做:
filter("*.html").through( SecurityCookieFilter.class );
但我的SecurityCookieFilter.doFilter
从未被调用过。我试过像"*.html*"
或<url-pattern>*</url-pattern>
这样的东西,但无济于事。知道我应该怎么做吗?
答案 0 :(得分:3)
您可能已将html文件配置为在appengine-web.xml中作为静态内容提供。静态文件服务根本不涉及您的应用程序,因此您无法过滤输出。
答案 1 :(得分:1)
如果你需要(像我的那样)让GAE为静态HTML文件添加某些http响应头,你可以通过在appengine-web.xml中将它们声明为静态资源来实现这一点:
<static-files>
<include path="/my_static-files" >
<http-header name="Access-Control-Allow-Origin" value="http://example.org" />
</include>
</static-files>
中找到了这个