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

来源:互联网 发布:阿里云直播demo 编辑:程序博客网 时间:2024/05/18 02:36


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等方式,日后用到时候再来补充





原创粉丝点击