<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.   

    第一个你如果是/result 只有/result他才会去跳转ACTION 如果是/ 的话  /TestResult 他就会就跳转action 里面没有配置 所有就跳转默认的hello.jsp第二是能访问hello.jps  还是r1.jsp
      

  2.   

    1、你的访问路经是存在问题的,如果用namespace的话访问的话需要用projectname/namespace/XX.action。默认不写就是你所说的namespace="/"
    2、能访问是因为你配了 <default-action-ref name="hello" /><!-- 默认状态下要转到的action -->
    你自己写的很清楚了,如果访问的路经不正确,会调用默认的action来转到你事先定义好的逻辑。
      

  3.   

    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 -->
      

  4.   

    我的意思是namespace里面配置namespace="/result",我在url里面输入localhost:8080/TestResult,是为了验证它能访问hello.jsp.但是xml里面没有namespace="/"是不是就不能访问到hello.jsp呀。我在url里面输入localhost:8080/TestResult/result.也不能访问到hello.jsp.
    第2个是r1.jsp。我的疑问是:在hello.jsp能正常访问的情形下,result/r1.它会访问r1这个result里的r1.jsp。但是我要把链接路径改为reult/kkk/kk/r1它也能正常访问到r1.jsp,这是为什么呀
    谢谢
      

  5.   

    引用 1 楼 的回复:
    第一个你如果是/result 只有/result他才会去跳转ACTION 如果是/ 的话 /TestResult 他就会就跳转action 里面没有配置 所有就跳转默认的hello.jsp第二是能访问hello.jps 还是r1.jsp我的意思是namespace里面配置namespace="/result",我在url里面输入localhost:8080/TestResult,是为了验证它能访问hello.jsp.但是xml里面没有namespace="/"是不是就不能访问到hello.jsp呀。我在url里面输入localhost:8080/TestResult/result.也不能访问到hello.jsp.
    第2个是r1.jsp。我的疑问是:在hello.jsp能正常访问的情形下,result/r1.它会访问r1这个result里的r1.jsp。但是我要把链接路径改为reult/kkk/kk/r1它也能正常访问到r1.jsp,这是为什么呀
    谢谢 
      

  6.   

    加上/result访问还是不可以是为什么呢?
    谢谢
      

  7.   

    第一 你输入8080/result/TestResult 就能访问了,他是判断你的第一个空间是否正确就像你输入8080TestResult那么你配置'/'也不会挑战 第二个问题 可能是中间的/kk/kk如果找不到 他会知道找到下面的r1 类似字符串的indexof只看里面是否含有 而不是完全去匹配