struts.xml 中的操作重定向
我可以从 struts actions 中重定向到另一个操作吗?因此,一个操作的结果是另一个操作,即 - 这是 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>
谢谢
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>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。您可以重定向,也可以链接。重定向从头开始,就像您第一次调用另一个操作一样,而链将值保留在值堆栈上并添加新操作的变量。
转发:
链接:
为了方便起见,可以将重定向结果类型更改为“redirectAction”结果类型...这让我们可以这样写:
最后一个可能就是您想要的。
现在有一个警告,链接/动作重定向与“goto”语句一起出现。不是邪恶的,但容易滥用,您可能应该考虑移动决定逻辑(确定要调用几个拦截器的操作的逻辑),或者如果逻辑主要与设置相关,则由拦截器调用的某种类型的实用程序类操作准备方法(或直接进入准备方法)...如果操作在调用准备之前需要参数,则使用 paramsPrepareParamsStack。
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.
To forward:
To chain:
As a convenience the redirect result type can be changed to a "redirectAction" result type... which lets us write:
This last one is probably what you want.
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.