Struts2中的Result基本用法
来源:互联网 发布:ubuntu vim设置 编辑:程序博客网 时间:2024/06/05 11:32
- 在Action中的Result有一个type属性,主要有4种常用的用法。
1.<result type="dispatcher">/DemoJsp1.jsp </result>
服务器端跳转,地址栏不改变。
传值的方法:
地址栏写:http://localhost:8080/strutsdemo/hoho/s1?t=1
JSP页面写:<s:property value="t"/>
struts.xml里写:<result type="dispatcher">/DemoJsp1.jsp </result>
就可接收到参数,因为服务器跳转,他们共用valueStack里的内容。 - 2.
<action name="s2"><result type="redirect">/DemoJsp2.jsp </result></action>
客户端跳转,地址栏改变。
传值的方法:
地址栏写:http://localhost:8080/strutsdemo/hoho/s2?t=1
<s:property value="#parameters.r"/>
struts.xml里写:<action name="s2" class="com.struts.app.Demo1"><result type="redirect">/DemoJsp2.jsp?r=${t} </result></action>
因为是客户端跳转,不存在ValueStack,所以把t的内容保存到Stack Context的parameters里了,通过#parameters.r就可调出该值。
下面两种方法传值同上。
3.<action name="s3"><result type="chain"> <param name="actionName">s1</param><!-- //要跳转的action名称, --> <param name="namespace">/hoho</param><!-- //要跳转的action所在的namespace地址 --></result></action>
可跳转至action,服务端跳转,地址栏不改变。
4.<action name="s4"><result type="redirectAction"> <param name="actionName">s2</param> <param name="namespace">/hoho</param></result></action>
可跳转至action,客户端跳转,地址栏改变。 - 可以在packaage里配置公共的Result,不用写action。我的类中是这样写的
<global-results><result name="main">/DemoJsp3.jsp</result></global-results>
package com.struts.app;import com.opensymphony.xwork2.ActionSupport;public class Demo1 extends ActionSupport{private int t;public int getT() {return t;}public void setT(int t) {this.t = t;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubif(t==1){return SUCCESS;}else{return "main";}}}
所以只要我输入的t不等于1,就返回main。就会调用global-result - 如果一个包中想调用别的包里的global-result,就修改package里的extends内容
<package name="hoho" namespace="/hoho" extends="struts-default"><global-results><result name="main">/DemoJsp3.jsp</result></global-results><action name="s1" class="com.struts.app.Demo1"><result type="dispatcher">/DemoJsp1.jsp </result></action></package><package name="rr" namespace="/rr" extends="hoho"><action name="s2" class="com.struts.app.Demo1"><result>/DemoJsp2.jsp </result></action></package>
包rr想用hoho的global-result就把extends修改成hoho.在大型项目中,多人可继承一个公共的result,就用这种方法。
0 0
- Struts2中的Result基本用法
- struts2中的result用法
- Struts2中的result类型
- struts2中的Stream Result
- struts2中的result配置
- Struts2中的Result类型--1
- struts2中的Result Type简介
- struts2自定义result中的type
- struts2中的result的总结
- Struts2.5 result中的chain
- struts2 全局result和动态result的用法
- struts2中常用Result类型的用法
- struts2中常用Result类型的用法
- struts2中常用Result类型的用法
- struts2常见的result类型的用法
- Struts2 result type="stream"的用法
- struts2中常用Result类型的用法
- struts2 Result类型和对应的用法
- Android Camera FW到Camera Hal调用流程
- Java使用字符流拷贝文件出现乱码
- 解决ScrollView下嵌套ListView、GridView显示不全的问题
- java泛型
- 线段树-HDU 1166 敌兵布阵
- Struts2中的Result基本用法
- linux内核模块编译
- 编译OK6410-A 的qt-everywhere-opensource-src-4.7.1出错 解决办法
- android开发--001
- (六)-UITableView几个方法的使用说明
- 动态规划之矩阵连乘问题
- linux vim 配置文件.vimrc
- github简单使用教程
- 2.循环链表和双向链表