【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
生活随笔
收集整理的這篇文章主要介紹了
【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Result學(xué)習(xí)筆記(三)帶參數(shù)的結(jié)果集
第一部分:代碼
//前端 <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">傳參數(shù)</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;}@Overridepublic 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">傳參數(shù)</a></li>,鏈接訪問user命名空間里面的user action,并對action傳遞參數(shù)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>? 目的: ? ? 跟據(jù)配置文件構(gòu)造user action對象,并進行設(shè)置參數(shù)。由client發(fā)出請求后,由web.xml的配置文件構(gòu)造UserAction對象時,請求中出傳遞的數(shù)值會傳遞到構(gòu)造的對象中。注意:一次request僅僅有一個值棧.? ? result要求<result type="redirect">/user_success.jsp?t=${type}</result>,要求重定向到到user_success.jsp,并要求去除
action中的type值。當(dāng)中type="redirect"表示是client跳轉(zhuǎn),
3.from valuestack: <s:property value="t"/><br/> //從值棧取值from actioncontext: <s:property value="#parameters.t"/> <span style="white-space:pre"> </span>//從actioncontext取值
總結(jié)
以上是生活随笔為你收集整理的【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库连接池-连接的关闭内幕
- 下一篇: 使用jenkins进行git多分支项目打