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