【web开发学习笔记】Structs2 Result学习笔记(三)带参数的结果集
2014-07-05 19:10
447 查看
Result学习笔记(三)带参数的结果集
第一部分:代码
//前端 <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>目的:
跟据配置文件构造user action对象,并进行设置参数。由客户端发出请求后,由web.xml的配置文件构造UserAction对象时,请求中出传递的数值会传递到构造的对象中。注意:一次request只有一个值栈.
result要求<result type="redirect">/user_success.jsp?t=${type}</result>,要求重定向到到user_success.jsp,并要求去除
action中的type值。其中type="redirect"表示是客户端跳转,
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学习笔记(二)动态结果集
- 【web开发学习笔记】Structs2 Result学习笔记(二)动态结果集
- 【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
- 【web开发学习笔记】Structs2 Result学习笔记(一)简单介绍
- UNIX网络编程学习笔记:值-结果(value-result)参数
- 【web开发学习笔记】Structs2 Action学习笔记(二)
- 【web开发学习笔记】Structs2 OGNL学习笔记
- 【web开发学习笔记】Structs2 Action学习笔记(两)
- 【web开发学习笔记】Structs2 Action学习笔记(一)
- 【web开发学习笔记】Structs2 Action学习笔记(一个)
- 【web开发学习笔记】Structs2 Action学习笔记(三)action通配符的使用
- 【web开发学习笔记】Structs2 Action学习笔记(四)include的使用
- 细雨学习笔记:Jmeter上一个请求的结果作为下一个请求的参数--使用正则提取器
- 可变参数学习笔记
- CSS学习笔记Padding 属性中参数的定义与使用
- CSS学习笔记Padding 属性中参数的定义与使用
- AJAX 学习笔记(7) 发送请求参数
- “UNIX系统开发-gcc参数详解学习笔记
- java学习笔记:参数传递(2)
- 学习笔记:[Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1。