struts2为什么只拦截.action的请求;而.do的请求拦截不到???
struts2为什么只拦截.action的请求;而.do的请求拦截不到???
请求路劲
http://127.0.0.1:8081/ibatisSpringStruts/loginAction.do
结果
HTTP Status 404 - /ibatisSpringStruts/loginAction.do
而我把配置
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
改为
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
则http://127.0.0.1:8081/ibatisSpringStruts/loginAction.action 可以请求到
下面是相关配置
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="xxx" extends="struts-default" namespace="/">
<action name="loginAction" class="org.ibatis.userAction">
<result name="success">/index.jsp</result>
<result name="no">/505.jsp</result>
</action>
</package>
</struts>
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
------解决方案-------------------- 引用: 默认是 拦截不到的。你可以自己配制
正如1楼说的default.properties中的这句
### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
struts.action.extension=action
------解决方案-------------------- struts.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<!-- 修改struts2访问链接的后缀名,改成.do的形式 -->
<constant name="struts.action.extension" value="do"></constant>
<!-- 修改struts2的UI主题,改为简单模式 -->
<constant name="struts.ui.theme" value="simple"></constant>
<!-- 修改struts2的开发模式,默认是false -->
<constant name="struts.devMode" value="false"></constant>
<!-- 修改struts2的字符编码 -->
<constant name="struts.i18n.encoding" value="utf-8"></constant>
<constant name="struts.action.extension" value="do"></constant>