//前端 <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030" /> <title>Insert title here</title> </head> <body> <ol> <li><a href="user/user?type=1">传参数</a></li> </ol> </body> </html>
//web.xml <struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.struts2.user.action.UserAction"> <result type="redirect">/user_success.jsp?t=${type}</result> </action> </package> </struts>
//类包 package com.struts2.user.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private int type; public int getType() { return type; } public void setType(int type) { this.type = type; } @Override public String execute() throws Exception { return "success"; } }
//展示 </head> <body> User Success! from valuestack: <s:property value="t"/><br/> from actioncontext: <s:property value="#parameters.t"/> <s:debug></s:debug> </body> </html>
1.<li><a href="user/user?type=1">传参数</a></li>,链接访问user命名空间里面的user action,并对action传递参数type = 1;
2.<package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.struts2.user.action.UserAction"> <result type="redirect">/user_success.jsp?t=${type}</result> </action> </package> <result type="redirect">/user_success.jsp?t=${type}</result>目的:
3.from valuestack: <s:property value="t"/><br/> //从值栈取值 from actioncontext: <s:property value="#parameters.t"/> <span style="white-space:pre"> </span>//从actioncontext取值
【web开发学习笔记】Structs2 Result学习笔记(三)带参数的结果集,布布扣,bubuko.com
【web开发学习笔记】Structs2 Result学习笔记(三)带参数的结果集
原文地址:http://blog.csdn.net/licong_carp/article/details/37072241