【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
生活随笔
收集整理的這篇文章主要介紹了
【web开发学习笔记】Structs2 Result学习笔记(三)带參数的结果集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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;}@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">傳參數</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對象,并進行設置參數。由client發出請求后,由web.xml的配置文件構造UserAction對象時,請求中出傳遞的數值會傳遞到構造的對象中。注意:一次request僅僅有一個值棧.? ? result要求<result type="redirect">/user_success.jsp?t=${type}</result>,要求重定向到到user_success.jsp,并要求去除
action中的type值。當中type="redirect"表示是client跳轉,
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学习笔记(三)带參数的结果集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库连接池-连接的关闭内幕
- 下一篇: 使用jenkins进行git多分支项目打