2012-04-14 67 views
3

我創建了一個Filter與請求對象和forward相應檢查Cookie S上的請求,由於thisthis question..Now我想,因爲我已經在web.xml宣佈它映射該Filter只是在welcome-file
說我有welcome-file作爲index.html那我也映射Filter兩個www.example.com/www.example.com/index.html,但不爲別的,如www.example.com/foo/*www.example.com/*是不允許的,我的意思是不是除了welcome-file要求任何東西。 我正在使用Apache Tomcat 7.0.22容器。如何爲Tomcat的web.xml中的welcome-file映射過濾器?

回答

2

只需添加這些到你的web.xml

<filter> 
    <filter-name>myFilter</filter-name> 
    <filter-class>com.examples.myFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>myFilter</filter-name> 
    <url-pattern>/index.html</url-pattern> 
</filter-mapping> 
+0

那麼這將是'www.example.com'情況下有用嗎?用URL模式不清楚哪些文件將由contanier提供? – AZB 2012-04-15 10:17:07

+0

是的,如果你沒有更改context.xml中的主機名。 '/'代表應用程序的根目錄,index.html將被提供,因爲您在歡迎文件中提到了相同內容,並且它應該位於WebContent文件夾 – Ravi 2012-04-15 15:42:09

+0

好的非常感謝 – AZB 2012-04-15 20:05:42