当前位置: 代码迷 >> Java Web开发 >> struts2 重定向有关问题(struts.xml)
  详细解决方案

struts2 重定向有关问题(struts.xml)

热度:5697   发布时间:2013-02-25 21:14:13.0
struts2 重定向问题(struts.xml)
本人最近接手一个代码 。。。在struts.xml 有些疑惑求解决:代码如下
<action name="loanProcessNew" class="loanProcessController" method="loanProcess">
<result name="success">/newcrm/customermodule/success.jsp</result>
<result name="chushen" type="redirect">showmaterial.action?custinfoid=${ov.customerId}&amp;ov.back=1</result>
<result name="fushen" type="redirect">orderverify.action? runningNumber=${ov.runningnumber}&amp;ov.back=1</result>
<result name="error" >error.jsp</result>
</action>

<action name="loanProcessNew2" class="loanProcessController" method="loanProcess">
<result name="success">/newcrm/customermodule/success.jsp</result>
<result name="chushen" type="redirect">showmaterialNew.action?custinfoid=${ov.customerId}&amp;ov.message=${ov.message}&amp;ov.comment=${ov.comment}</result>
<result name="fushen" type="redirect">orderverify.action?runningNumber=${ov.runningnumber}&amp;ov.message=${ov.message}&amp;ov.comment=${ov.comment}</result>
<result name="error" >error.jsp</result>
</action>
2个action 同一个类下的同一个方法 中间2个result 是什么意思? 重定向后怎么找到对应的action 。。。详细越好 谢谢 大侠们

------解决方案--------------------------------------------------------
<action name="loanProcessNew" class="loanProcessController" method="loanProcess">
根据你name="loanProcessNew"这个action来找class="loanProcessController"这个类的method="loanProcess">这个方法。这个方法一般是String类型的返回值。比如你返回的是"success"那么就会去<result >里面找一个name="success"的。当然name="success"这个是默认的。可以省略不写如<result name="success">/index.jsp</result>可以改成<result>/index.jsp</result>
------解决方案--------------------------------------------------------
重定向到对应的action 可以这样

<result name="SUCCESS"type="redirectAction">namespace/actionName</result>

如果你要重定向到相同的配置文件下面的其他action可以去掉namespace 直接填写/ action的Name

如果要重定向到其他配置文件下面的action,比如namespace为/user,则为../user/action的Name
------解决方案--------------------------------------------------------
<action name="loanProcessNew" class="loanProcessController" method="loanProcess">
 <result name="chushen" type="redirect">showmaterial.action</result>
</action>
属性type="redirect"石用来跳转到另一个Action的,showmaterial.action就是另一个Action,其中showmaterial要和另一个Action的name相对应,例如跳转到:
<action name="showmaterial" class="" method=""></action>

------解决方案--------------------------------------------------------
name对应的值和你方法返回的字符串一直。
<action name="loanProcessNew" class="loanProcessController" method="loanProcess">
 <result name="chushen" type="redirect">showmaterial.action</result>
</action>
要重定向到一个action的时候需要修改一下type的类型 例如上例 showmaterial.action这个是你要重定向的ACTION。。
------解决方案--------------------------------------------------------
两个result 是什么意思?

根据action的返回值不同,定向到不同的地方。


Java code
<action name="loanProcessNew" class="loanProcessController" method="loanProcess">    <result name="success">/newcrm/customermodule/success.jsp</result>    <result name="chushen" type="redirect">showmaterial.action?custinfoid=${ov.customerId}&amp;ov.back=1</result>    .........</action>
  相关解决方案