struts.xml 中的动作重定向 [英] Action redirect in struts.xml

查看:35
本文介绍了struts.xml 中的动作重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从 struts 动作中重定向到另一个动作吗?所以一个动作的结果是另一个动作,即 - 这里是 struts.xml 的一个片段

Can I redirect to another action from within a struts actions ? So the result of an action is another action i.e - here is a snippet of struts.xml

    <action name="newRedirect" >
        <result>formsearch</result>
    </action>

    <action name="formsearch" class="com.event.action.SearchForm"
    method="execute">
        <result name="success">/form.jsp</result>
    </action>

谢谢

推荐答案

是的.您可以重定向,也可以链接.重定向从头开始,就像你第一次调用另一个动作,而链将值保留在值堆栈上并添加新动作的变量.

Yes. You can redirect and you can chain. Redirect starts from scratch, it is like you called the other action for the first time while chain keeps the values on the value stack and adds the variables of the new action.

转发:

<action name="newRedirect" >
    <result type="redirect">/formsearch.action</result>
</action>

链接:

<action name="newRedirect" >
    <result type="chain">formsearch</result>
</action>

为方便起见,重定向结果类型可以更改为redirectAction"结果类型...这让我们可以这样写:

As a convenience the redirect result type can be changed to a "redirectAction" result type... which lets us write:

 <action name="newRedirect" >
    <result type="redirectAction">formsearch</result>
</action>

这最后一个可能就是你想要的.

This last one is probably what you want.

现在警告,链接/动作重定向与goto"语句一起出现.不是邪恶但容易滥用,您可能应该考虑移动决定逻辑(确定要调用多个拦截器的操作的逻辑),或者如果逻辑主要与设置相关,则由调用的某种类型的实用程序类动作准备方法(或直接进入准备方法)...如果在调用准备之前动作需要参数,则使用paramsPrepareParamsStack.

Now a warning, chaining/action redirection is up there with the "goto" statement. Not evil but easy to abuse, you should probably look to moving the deciding logic (the logic that determines what action to call of several to an interceptor) or if the logic is mostly setup related then some type of utility class that is invoked by the actions prepare method (or into the prepare method outright)... If the action needs parameters before prepare is called then use the paramsPrepareParamsStack.

这篇关于struts.xml 中的动作重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆