我的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结尾的吧,为什么我这里不加这句话就访问不到呢???

解决方案 »

  1.   

    <package name="strtus2TestOne" namespace="/"  extends="struts-default">
    命名空间加个"/"试试~
      

  2.   

    <package name="" namespace="/" extends="struts-default">
    命名空间加个"/",包名去掉,再试试~
      

  3.   

    请教LZ一个问题 你用的是Spring吗?能否推荐一本书 谢谢!~
      

  4.   

    <action name="struts2Test_" class="struts2TestAction">
    http://localhost:8089/ssh/struts2Test_execute.action
    试试,报错是找不到ACTION么
      

  5.   

    另外你spring里配置了struts2TestAction了么
      

  6.   

    楼上的,我和你说,现在的问题是我描述的:最后我在struts.xml文件加了一句:  <constant name="struts.action.extension" value="do,action" />我再用:http://localhost:8089/ssh/struts2Test!execute.action
    访问,可以了
    所以肯定不是你说的这些现象。你要是很有兴趣,你要么和我一样,搭建起来看看吧