你的位置:首页 > 软件开发 > Java > struts2 中redirectAction如何传递参数!

struts2 中redirectAction如何传递参数!

发布时间:2016-03-06 11:00:16
在struts2中,初学者因为参数传递的问题往往会出现一些错误。比如页面跳转的问题,在用户注册中,以一下代码作为案例:<struts> <constant name="struts.action.extension" value=&quot ...

在struts2中,初学者因为参数传递的问题往往会出现一些错误。

比如页面跳转的问题,在用户注册中,以一下代码作为案例:

<struts>  <constant name="struts.action.extension" value="action,,"></constant>  <constant name="struts.devMode " value="true"></constant>   <constant name="struts.enable.DynamicMethodInvocation" value="true" />   <package name="user" namespace="/" extends="struts-default">    <action name="*" class="user.TotalAction" method="{1}" >      <result name="success">/WEB-INF/user/userlist.jsp</result>      <result name="modify">/WEB-INF/user/modifyit.jsp</result>       <result name="list" type="redirectAction">userlist</result>    </action>  </package></struts>
调用{@link HttpServletResponse#sendRedirect(String) sendRedirect}方法来转到指定的位置. HTTP响应被告知使浏览器直接跳转到指定的位置(产生客户端的一个新请求). 这样做的结果会使刚刚执行的action(包括action实例,action中的错误消息等)丢失, 不再可用. 这是因为action是建立在单线程模型基础上的. 传递数据的唯一方式就是通过Session或者可以为Ognl表达式web参数(url?name=value)

  • location (默认) - action执行后跳转的地址.
  • parse - 默认为true. 如果设置为false, location参数不会被当作Ognl表达式解析.

 

二。当使用type=“redirectAction” 或type=“redirect”提交到一个action并且需要传递一个参数时。这里是有区别的:

原标题:struts2 中redirectAction如何传递参数!

关键词:Struts

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录