Struts2攔截.do後綴

最近因工做須要,要把原來配好請求路徑中沒有後綴的請求,改爲自定義後綴的請求。web

舉個栗子:   原來的請求路徑是  http://localhost:8080/test/indexspring

                     須要修改爲   http://localhost:8080/test/index.doapi

咱們的項目使用了第三方框架,鑑於保密須要,這裏不便告訴你們是什麼框架。app

框架中使用了spring-security作登陸以及統一控制的其餘攔截。框架

因此須要修改幾處配置async

1.web.xml配置url

增長.do攔截配置spa

<filter>
        <async-supported>true</async-supported>
        <filter-name>strutsPrepareFilter</filter-name>
        <filter-class>org.xxx.core.servlet.DelegatingFilter</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>excludePatterns</param-name>
            <param-value>/remoting/*,/api/*</param-value>
        </init-param>
    </filter>xml

<filter>
        <async-supported>true</async-supported>
        <filter-name>strutsExecuteFilter</filter-name>
        <filter-class>org.xxx.core.servlet.DelegatingFilter</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>excludePatterns</param-name>
            <param-value>/remoting/*,/api/*</param-value>
        </init-param>
    </filter>
    <filter>
        <async-supported>true</async-supported>
        <filter-name>sitemeshFilter</filter-name>
        <filter-class>org.xxx.core.servlet.DelegatingFilter</filter-class>
        <init-param>  
            <param-name>targetFilterLifecycle</param-name>  
            <param-value>true</param-value>  
        </init-param>
        <init-param>
            <param-name>excludePatterns</param-name>
            <param-value>/remoting/*,/api/*</param-value>
        </init-param>
        <init-param>
            <param-name>configFile</param-name>
            <param-value>resources/sitemesh/sitemesh.xml</param-value>
        </init-param>
    </filter>rem

<filter-mapping>
        <filter-name>strutsPrepareFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>sitemeshFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>strutsExecuteFilter</filter-name>
        <url-pattern>*.do</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
 

2.修改struts配置

增長 <constant name="struts.action.extension" value="do" />

 

3.spring-security配置

 <security:http pattern="/test/**" security="none" />

4.sitemesh配置

<decorators defaultdir="/resources/view/decorator"> 
    <decorator name="main" page="main.ftl">
        <pattern>*.do</pattern>
    </decorator>
</decorators>

 

這樣,咱們寫好Action以後,就能用 .do後綴進行訪問了。本文由於使用了框架,多作了些配置,實際應用中,應該根據您的須要來作相應配置。

 

本博客文章大可能是經驗積累總結,以避免從此忘卻,記錄下來。同時感謝您的閱讀,也但願能對您有所幫助。

相關文章
相關標籤/搜索