Struts2学习第六天:Result总结
来源:互联网 发布:英语学霸软件 编辑:程序博客网 时间:2024/05/22 14:44
/Struts2_1600_GlobalResult 公用的结果集
1.如果在加载过程中struts.xml文件配置错误,则必须重新加载项目。
<constant name="struts.devMode" value="true"/> 仅用于加载没问题Struts2帮助文档:\struts-2.1.6-all\struts-2.1.6\docs index.html
2.全局结果集:在struts.xml的package中配置:在extends ActionSupport 的类中写个返回String “main”的方法即可
<global-results> <result name="main"> /main.jsp </result> </global-results>
3.从一个package访问另一个package的 globalresult可通过extends属性
<package name="admin" namespace="/admin" extends="user"><package name="user" namespace="/user" extends="struts-default"> 默认的继承
必须有extends该属性,在referenced library/struts2-core-2.1.6.jar/struts-default.xml
/Struts2_1700_DynamicResult 动态结果集,使用不多,了解即可:
可以属性保存结果(r);属性的结果可以动态确定;在Struts.xml可以${r} 从值栈取值
1. 在Struts.xml中配置result如下:
<result>${r}</result> 不是EL表达式,是OGN表达式 $用于在配置文件中,从值栈中取值
2.在Controller中配置:
type通过index.jsp < li>< a href=”user/user?type=1”>返回success < / a> < / l i >
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; } @Override public String execute() throws Exception { if(type == 1) r="/user_success.jsp"; else if (type == 2) r="/user_error.jsp"; return "success"; } }
/Struts2_1800_ResultWithParams
1.配置struts.xml
<result type="redirect">/user_success.jsp?t=${type}</result>
是客户端跳转,只有在redirect(客户端)时才需要传
一个Action forward 到其他的Action,不需要传参数,forward共享同一个值栈
一次request只有一个值栈 因而采用 dispatcher 不需要传参数,可直接取值
2.在Action中声明type
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"; } }
3.在jsp中取值
from valuestack: <s:property value="t"/><br/><!- - 第一个取不到,因为新的请求没有Action的存在,t的参数无法放在值栈 - ->from actioncontext: <s:property value="#parameters.t"/><!- - 可以取到, - ->
2.Result总结
1. 常用四种类型:
a) dispatcher(默认) b) redirect c) chain d) redirectAction
2. 全局结果集
a) global-results | extends
3. 动态结果(了解)
a) 在action中保存一个属性,存储具体的结果location
4. 传递参数
a) 客户端跳转才需要传递 b) ${}表达式(不是EL)
阅读全文
0 0
- Struts2学习第六天:Result总结
- Struts2 Result总结
- Struts2 Result 总结
- Struts2 Action&Result 总结
- struts2学习_第六天(小知识总结)
- Struts2学习 Result
- struts2中的result的总结
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
- Struts2学习---result结果集
- Dom第六天学习总结
- struts2零配置中@result跳转总结
- Struts2总结之Action和Result
- struts2注解总结----@Action和@Result
- Struts2框架的总结一------Action&Result
- struts2注解总结----@Action和@Result
- struts2注解总结----@Action和@Result
- Struts2总结之Action和Result
- struts2注解总结----@Action和@Result
- Pymol(1.8.6)作图技巧之cartoon和surface镶嵌模型
- QQ侧滑菜单的实现和拓展-DrawerLayout
- HDU 3336 Count the strings(KMP+DP)
- 第一篇
- 关注民生民情
- Struts2学习第六天:Result总结
- 关注民生民情
- 线性表之循环链表、双向链表(三)--C语言实现
- python的基础知识
- 最新OmniPeek无线驱动详细列表与下载说明/支持捉空口包的网卡
- SonarQube代码质量管理平台的安装
- 自己手写的滑块验证码,前端签证码。因为极验验证好像要收费,自己纯手工打造,大家可以自己在这个基础上改进
- C++ 参考手册
- UVA Live 4732 Jinhan 带权并查集 2009 Asia Seoul Regional