Struts2之Result
来源:互联网 发布:winzip mac 6 注册机 编辑:程序博客网 时间:2024/04/27 23:39
Result类型
Struts2.xml代码:
还有一个:
then UserAction.java:
and then struts.xml:
last user_success.jsp:
- dispatcher (默认的)
- redirect
- chain
- redirectAction
- freemarker
- httpheader
- stream
- velocity
- xslt
- plaintext
- tiles
<body>Result类型<ol><li><a href="r/r1">dispatcher</a></li><li><a href="r/r2">redirect</a></li><li><a href="r/r3">chain</a></li><li><a href="r/r4">redirectAction</a></li><li>freemarker</li><li>httpheader</li><li>stream</li><li>velocity</li><li>xslt</li><li>plaintext</li><li>tiles</li></ol></body>
再上struts.xml:
<struts> <constant name="struts.devMode" value="true" /> <package name="resultTypes" namespace="/r" extends="struts-default"> <action name="r1"> <result type="dispatcher">/r1.jsp</result><!-- 服务器端跳转dispatcher只能到视图,不能到Action,就是servlet --> </action> <action name="r2"> <result type="redirect">/r2.jsp</result><!-- 客户端跳转。同上 --> </action> <action name="r3"> <result type="chain">r1</result> </action> <action name="r4"> <result type="redirectAction">r2</result> </action> </package></struts>
GlobalResult-
index.htnl代码:
<body>Result类型<ol><li><a href="user/user?type=1">返回success</a></li><li><a href="user/user?type=2">返回error</a></li><li><a href="user/user?type=3">返回global result</a></li><li><a href="admin/admin">admin,继承user包</a></li></ol></body>
Struts2.xml代码:
<struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <global-results> <result name="mainpage">/main.jsp</result> </global-results> <action name="index"> <result>/index.jsp</result> </action> <action name="user" class="com.china.UserAction"> <result>/user_success.jsp</result> <result name="error">/user_error.jsp</result> </action> </package> <package name="admin" namespace="/admin" extends="user"> <action name="admin" class="com.china.AdminAction"> <result>/admin.jsp</result> </action> </package></struts>
几个用到的java程序:
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 {if(type == 1) return "success";else if (type == 2) return "error";else return "mainpage";}}
还有一个:
import com.opensymphony.xwork2.ActionSupport;public class AdminAction extends ActionSupport {@Overridepublic String execute() throws Exception {return "mainpage";}}
DynamicResult动态结果集:(了解的级别)
first index.jsp:
<body>动态结果一定不要忘了为动态结果的保存值设置set get方法<ol><li><a href="user/user?type=1">返回success</a></li><li><a href="user/user?type=2">返回error</a></li></ol></body>
then UserAction.java:
mport com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {private int type;private String r;public String getR() {return r;}public void setR(String r) {this.r = r;}public int getType() {return type;}public void setType(int type) {this.type = type;}@Overridepublic String execute() throws Exception {if(type == 1) r="/user_success.jsp";else if (type == 2) r="/user_error.jsp";return "success";}}
last struts2.xml:
<struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.china.UserAction"> <result>${r}</result> </action> </package> </struts>
ResultWithParams:
frist index.jsp:
<body>向结果传参数<ol><li><a href="user/user?type=1">传参数</a></li></ol></body>
then UserAction.java:
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";}}
and then struts.xml:
<struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.china.UserAction"> <result type="redirect">/user_success.jsp?t=${type}</result> </action> </package> </struts>
last user_success.jsp:
<body>User Success!</br>from valuestack: <s:property value="t"/><br/><!--this is wrong,can't receiver-->from actioncontext: <s:property value="#parameters.t"/><s:debug></s:debug></body>
- Struts2之Result
- Struts2之Result详解
- Struts2之Result详解
- Struts2之Result详解
- Struts2之Result详解
- Struts2之Result详解
- Struts2之Result详解
- Struts2之Result详解
- Struts2 之 action/result设置
- (5)Struts2之Result
- Struts2笔记三之Result
- Struts2之result的配置
- 《研磨struts2》第五章 Result 之 5.1 Result基础
- 《研磨struts2》第五章 Result 之 5.3 全局Result
- 《研磨struts2》第五章 Result 之 5.7 自定义Result
- Struts2基础之十:全局result、动态指定result
- 道听途说Struts2之16:global result
- Struts2慢慢学之八----Result
- char,varchar,nvarchar有什么区别
- Qt 4 mysql 编译插件 测试 QSqlDatabase: QMYSQL driver not loaded
- (高精度) Round and Round We Go (1047)
- Windows硬盘安装Ubuntu双系统及Android开发环境搭建
- 利用ffmpeg编h264 (baseline)
- Struts2之Result
- AVI文件头格式浅析-计算音视频播放时长
- Linux下Bind error: Address already in use处理
- struts2 拦截器
- linux 下 nload -- 显示当前网络使用情况
- 18.log4j.properties例子:ConsoleAppender综合例子
- cmd常用命令
- 二分法 排序
- 多线程架构图