Struts2拦截.do后缀

最近因工作需要,要把原来配好请求路径中没有后缀的请求,改成自定义后缀的请求。

举个栗子:   原来的请求路径是  http://localhost:8080/test/index

                     需要修改成   http://localhost:8080/test/index.do

我们的项目使用了第三方框架,鉴于保密需要,这里不便告诉大家是什么框架。

框架中使用了spring-security做登录以及统一控制的其他拦截。

所以需要修改几处配置

1.web.xml配置

增加.do拦截配置

<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>

<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>

<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后缀进行访问了。本文因为使用了框架,多做了些配置,实际应用中,应该根据您的需要来做相应配置。

 

本博客文章大多是经验积累总结,以免今后忘却,记录下来。同时感谢您的阅读,也希望能对您有所帮助。

 

 

                                

                                         

转载于:https://my.oschina.net/u/2457585/blog/888782

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值