日期:2014-05-19  浏览次数:20794 次

小弟求解几个关于struts2的struts.xml问题
XML code


<struts>

 <!-- 这里面要做的是各种result类型 -->
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/result" extends="struts-default">

        <default-action-ref name="hello" /><!-- 默认状态下要转到的action -->
           <action name="hello">
                  <result>/hello.jsp </result>
           </action>
      
      <action name="r1">
      <result type="dispatcher">/r1.jsp</result>
      </action>
      
      <action name="r2">
      <result type="redirect">/r2.jsp</result>
      </action>
      
      <action name="r3">
      <result type="chain">r1</result>
      </action>
      
      <action name="r4">
      <result type="redirectAction">r2</result>
      </action>
    </package>
</struts>




hello.jsp文件是:
<body>
  <a href="result/kkkkk/r1">dispatcher</a> <br/>
  <a href="result/r2">redirect</a> <br/>
  <a href="result/r3">chain</a> <br/>
  <a href="result/r4">redirectAction</a> <br/>
  </body>

问题:
1.我在url中输入localhost:8080/TestResult回车,为什么显示不了hello.jsp页面,而把xml文件里的namespace改成namespace="/"就可以了?
2在namespace="/"的情况下,我点hello.jsp的第一个链接,明明我xml里没有result这个路径可是也能正确访问为什么吗?
求指点,谢谢。

------解决方案--------------------
1、你的访问路经是存在问题的,如果用namespace的话访问的话需要用projectname/namespace/XX.action。默认不写就是你所说的namespace="/"
2、能访问是因为你配了 <default-action-ref name="hello" /><!-- 默认状态下要转到的action -->
你自己写的很清楚了,如果访问的路经不正确,会调用默认的action来转到你事先定义好的逻辑。
------解决方案--------------------
1.我在url中输入localhost:8080/TestResult回车,显示不了hello.jsp页面,是因为namesapce="/result",这是你需要localhost:8080/TestResult/result,才能正确访问。 而把xml文件里的namespace改成namespace="/",访问方式就是localhost:8080/TestResult。

2在namespace="/"的情况下,我点hello.jsp的第一个链接,明明我xml里没有result这个路径可是也能正确访问,是因为有这条语句 <default-action-ref name="hello" /><!-- 默认状态下要转到的action -->
------解决方案--------------------
探讨

1.我在url中输入localhost:8080/TestResult回车,显示不了hello.jsp页面,是因为namesapce="/result",这是你需要localhost:8080/TestResult/result,才能正确访问。 而把xml文件里的namespace改成namespace="/",访问方式就是localhost:8080/TestResult。

2在name……