最近因工做须要,要把原来配好请求路径中没有后缀的请求,改为自定义后缀的请求。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后缀进行访问了。本文由于使用了框架,多作了些配置,实际应用中,应该根据您的须要来作相应配置。
本博客文章大可能是经验积累总结,以避免从此忘却,记录下来。同时感谢您的阅读,也但愿能对您有所帮助。