2010-05-05 81 views
3

首先,我使用的是Google AppEngine和Guice,但我懷疑我的問題與這些不相關。如何直接提供HTML頁面時應用servlet過濾器?

當用戶連接到我的(GWT)web應用程序時,該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> 

由於我使用吉斯,我要在我的servlet配置額外的過濾器,在那裏我做這個:

filter("*.html").through(SecurityCookieFilter.class); 

但是我的SecurityCookieFilter.doFilter永遠不會被調用。我嘗試了諸如"*.html*"<url-pattern>*</url-pattern>之類的東西,但無濟於事。任何想法我應該如何做到這一點?

+0

我發現它通過切換到「.jsp」而不是「.html」。 – 2010-05-05 03:44:05

回答

3

您可能已將HTML文件配置爲您的appengine-web.xml中的靜態內容。靜態文件服務根本不涉及您的應用程序,因此您無法過濾輸出。

+0

謝謝。我已經在那裏添加了appengine-web.xml。有什麼遺漏? – 2010-05-05 20:57:05

+0

它看起來像你的HTML被作爲一個靜態文件,正如我所說,這意味着它根本不會觸及你的代碼。你需要創建一個servlet來提供你的文件,如果你希望它們是後處理的。 – 2010-05-05 22:35:13

1

如果你的需要剛好是(像我),使GAE添加某些HTTP響應頭的靜態HTML文件,您可以通過聲明爲靜態資源在AppEngine上-web.xml中這樣做:

<static-files> 
    <include path="/my_static-files" > 
    <http-header name="Access-Control-Allow-Origin" value="http://example.org" /> 
    </include> 
</static-files> 

我發現這在GAE documentation

+0

歡呼,因爲它可以爲人們節省很多麻煩。不幸的是,對我來說,這有點害羞,因爲我想301域名的重定向(從www到裸體),所以如果他們支持域屬性,就像他們做了一條路徑一樣,那將是完美的服務位置標題)。但是AFAIK(在閱讀了其他文檔後),這是不可能的 – 2017-05-08 11:05:55