struts2中怎么从一个action跳到另一个action

来源:百度知道 编辑:UC知道 时间:2024/06/25 20:52:45
<package name="action" extends="struts-default" namespace="/action">
<action name="list" class="action.ListAction">
<result>/action/show.action</result>
</action>
<action name="show" class="action.ShowAction">
<result>/index.jsp</result>
</action>
</package>

就像上面大,我想从ListAction跳到ShowAction这样写问什么不行,为什么会报出 /test/action/show.action(注:contextPath=test),如果我把这一段替换成/action/show.jsp就可以,请高手指点迷津
补充一下,上面大那个 /test/action/show.action(注:contextPath=test) ,是无效路径

action 中/就代表/test了,
/test/action/show.jsp这样 就相当于/test/test/action/show.jsp了

默认的结果类型是渲染(dispatcher),即渲染一个jsp页面。<result type="..."></result>中type指的就是结果类型。所以在你不填type的时候,系统把结果当作jsp文件来处理,因此出错。
你所需要的结果类型是重新跳转到一个action(Redirect Action Result),需要type="redirectAction"。(注意:某些历史struts2版本使用的是redirect-action,现在的2.1.6版本使用的是redirectAction)然后设置参数即可:
<result type="redirectAction">
<param name="actionName">show</param>
<param name="namespace">/action</param>
</result>
看来你对struts2的结果类型的知识还需要提高。赶紧把所有结果类型都看一下,有几个是很重要的,比如客户端透明的action跳转、某网址的跳转、返回http头、返回Stream流等。参考官网的网址见下。

action的跳转 不能那样写
应该 <result type="chain">action的名字就可以</...

初入江湖的<result type="redirect-action">是重定向到另一个action
原先的action的 值会丢失