我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- begin Spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml;</param-value>
</context-param> <filter>
<filter-name>ssh</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>ssh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
。
2:我的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> <constant name="struts.multipart.maxSize" value="4194304" />
<package name="strtus2TestOne" namespace="" extends="struts-default">
<action name="struts2Test" class="struts2TestAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
</struts>
3:我要说明下,我的配置应该是没有问题的,应该接下来我要说明下我奇怪的问题所在:
我在项目启动以后访问:http://localhost:8089/ssh/struts2Test!execute.action
不行,报404错误.然后我想了很多办法,最后我在struts.xml文件加了一句: <constant name="struts.action.extension" value="do,action" />我再用:http://localhost:8089/ssh/struts2Test!execute.action
访问,可以了。我的问题是:strtus2应该默认是.action结尾的吧,为什么我这里不加这句话就访问不到呢???
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- begin Spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml;</param-value>
</context-param> <filter>
<filter-name>ssh</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>ssh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
。
2:我的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> <constant name="struts.multipart.maxSize" value="4194304" />
<package name="strtus2TestOne" namespace="" extends="struts-default">
<action name="struts2Test" class="struts2TestAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
</struts>
3:我要说明下,我的配置应该是没有问题的,应该接下来我要说明下我奇怪的问题所在:
我在项目启动以后访问:http://localhost:8089/ssh/struts2Test!execute.action
不行,报404错误.然后我想了很多办法,最后我在struts.xml文件加了一句: <constant name="struts.action.extension" value="do,action" />我再用:http://localhost:8089/ssh/struts2Test!execute.action
访问,可以了。我的问题是:strtus2应该默认是.action结尾的吧,为什么我这里不加这句话就访问不到呢???
命名空间加个"/"试试~
命名空间加个"/",包名去掉,再试试~
http://localhost:8089/ssh/struts2Test_execute.action
试试,报错是找不到ACTION么
访问,可以了
所以肯定不是你说的这些现象。你要是很有兴趣,你要么和我一样,搭建起来看看吧