您的位置:首页 > 编程语言 > Java开发

Struts2基础之九:result的服务器跳转和客户端跳转

2012-10-14 22:34 423 查看
struts.xml 中配置action返回结果的方式:

一:跳转到页面

如果<result>标签没有指定type的话,默认是<result type="dispatcher">,也就是服务器端页面跳转

<!-- 1:服务器端跳转 -->
<!-- 跳转后URL显示:还是action名(不变) -->
<action name="hello1">
<result type="dispatcher">
/helloStruts2.jsp
</result>
</action>
<!-- 2:客户端跳转 -->
<!-- 跳转后URL显示:下边的jsp名(变为映射的jsp名) -->
<action name="hello2">
<result type="redirect">
/helloStruts2.jsp
</result>
</action>


二:跳转到其他action

<!-- 1:服务器端跳转到目的action -->
<!-- 跳转后URL显示:所请求的action名(不随跳转变) -->
<action name="hello3">
<result type="chain">
hello1
</result>
</action>
<!-- 2:客户端跳转到目的action -->
<!-- 跳转后URL显示:目的action的jsp名(变为映射的jsp名) -->
<action name="hello4">
<result type="redirectAction">
hello1
</result>
</action>


其中chain方式,如果要跳转到其他包内的action比较麻烦,要多配置一个参数:

<result type="chain">
<param name="actionName">dashboard</param>
<param name="namespace">/secure</param>
</result>


三:其他方式

还有stream方式(下载时候要配置),FreeMarker等方式,日后用到时候再来补充
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息