日期:2014-05-18  浏览次数:20603 次

struts2.0 控制重定向问题!
struts2.0有那几种重定向的方式?
还有没有struts1.3里面的ActionForward()方法重定向?

我要实现的功能是,一个action处理完业务 但是不确定要重定向到那个jsp去
要根据数据库的地址才能决定 配置文件只能控制一个 不能灵活的控制 请问怎么实现这样的重定向???

------解决方案--------------------
根据你的action的中return的结果对应不同的返回页面呀在result中实现
XML code
<action name="">
<result name="c1">/**.jsp</result>
<result name="c2">/**.jsp</result><result name="c2">/**.jsp</result>
<result name="c4">/**.jsp</result>
</action>

------解决方案--------------------
struts2重定向:

1>.重定向JSP

<action name="" method="" class="">
<result type="redirect">重定向jsp</result>
</action

2>.重定向Action

<action name="" method="" class="">
<result type="redirectAction">
<param name="actionName">重定向ActionName</param>
<param name="namespace">重定向ActionName所在命名空间</param>
</result>
</action
------解决方案--------------------
探讨
Java code
ActionForward forward = new ActionForward();
path = "/games/main.jsp";
path = path + "?gamemode=" + role.getGamemode();
forward.setPath(path);
forward.setRedirect(true);
return forward;




这样可以从action控制跳转路径,我写的个写死的,你根据你的数据拼装路径就行了

------解决方案--------------------
晕,没写完就发了,在写下。。。

可以这么解决。比如urlString存的是你从数据库中取出来要跳转的页面。 
在xml配置文件中你可以这么写。 

<action name="***" class="***" method="****">
<result name="success" type="redirect">${urlString}</result>
</action>

假设我的urlString 为http://www.sohu.com/ 
他就跳转到sohu的网页去了。是跳转到外站必须要加上http://,本地工程就不用了,得到的字符串中路径什么的都是对的就可以了。
如果你的urlString为另外一个action的名字,假设为123.action,也是这样的写法。
如果你的urlString是<action name="qwer" class="***" method="****">中的name的值qwer 就应该这样写

<action name="***" class="***" method="****">
<result name="success" type="redirectAction">${urlString}</result>
</action>