05 dispatcher redirect chain redirectAction的使用

来源:互联网 发布:建筑设计院软件 编辑:程序博客网 时间:2024/04/30 07:38

1.   修改struts.xml

      <action name="user_dispatcher">

           <result type="dispatcher">/Adminadd_success.jsp</result>

        </action>

       

        <action name="user_redirect">

            <result type="redirect">/Adminadd_success.jsp</result>

        </action>

       

        <action name="user_chain">

            <result type="chain">user_redirect</result>

        </action>

       

        <action name="user_redirectAction">

            <result type="redirectAction">user_dispatcher</result>

</action>

2.   运行

启动tomcat

1)        访问http://localhost:2000/Gao_struts2/struts/user_dispatcher.action

     页面显示:user addsuccess!

     页面地址依然是:http://localhost:2000/Gao_struts2/struts/user_dispatcher.action

2)       访问:http://localhost:2000/Gao_struts2/struts/user_redirect.action
 页面显示:user add success!
  
页面地址改为:http://localhost:2000/Gao_struts2/Adminadd_success.jsp

3)        访问:http://localhost:2000/Gao_struts2/struts/user_chain.action

 页面显示:user add success!

 页面地址改为:http://localhost:2000/Gao_struts2/Adminadd_success.jsp

4)        访问:http://localhost:2000/Gao_struts2/struts/user_redirectAction.action

 页面显示:user add success!

     页面地址改为:http://localhost:2000/Gao_struts2/struts/user_dispatcher.action

3.   总结

1)        dispatcherredirect用于action跳转到页面。

2)        chainredirectAction用于action跳转到action

3)        dispatcherchain是服务器端跳转,所以他们不会改变客户端浏览器中访问的地址。

4)        redirectredirectAction是客户端跳转,就是说客户端发起action的请求后,服务端会返回action返回的对应的地址给客户  端,客户端会再次发起新的请求给服务器,其中客户端浏览器的地址就是客户端最后访问服务端的地址。