struts2為什麼filter不能過濾.action的請求
最近做專案,碰到一個問題,需要弄個過濾器或者是攔截器之類的功能。以我暫時的能力只能把攔截器配置在struts.xml中,為了不改變當前Struts.xml的內容,
就打算用過濾器filter,其實很簡單,不過也是巧。先在web.xml中配置了過濾器
<filter>
<filter-name>pppfilter</filter-name>
<filter-class>com/fs.filter.LFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>pppfilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
因為我的配置的時候比較急,把這個配置在了最上面,具體說就是在struts總過濾器的上面,就在java中寫了過濾器。
public class LFilter implements Filter{
public void init(FilterConfig filterConfig) throws ServletException{
}
public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain)
throws IOException,ServletException{
。。。。
}
。。。
}
然後就跑通了,正如預期一樣,沒什麼問題,
然後功能啥的正確了,就看到web.xml中的過濾器位置不正確,就打算整理一下,結果吧struts的過濾器和自定義過濾器換過來了,即struts的在前,自定義的在後,結果就是出錯了,後來找了原因,把<url-pattern>*.action</url-pattern>中的*.action換成/*就可以了,但是問題是css檔案和js檔案都過來,這樣的話,我想肯定會影響請求的速度,後來就把那個自定義的換到前面去了,而且web,xml中的過濾條件就是*.action。我搞不清楚這是什麼情況,看了下struts1.確實是struts定義在前,自定義在後的,為什麼到了struts2就必須交換位置呢,暫時解決不了,先記錄下。