struts2中XML配置中result的值
来源:互联网 发布:剑网三炮哥捏脸数据 编辑:程序博客网 时间:2024/05/17 20:08
result中的常见值得配置。
1.dispatcher 配置如下所示
<result name="welcome" type="dispatcher">/welcome.jsp</result>
作用:我们在A页面填写相关的数据,提交到后台的Action做以处理,然后将A页面填写的数据返回到相关的welcome页面。也就是说,可以将A页面中的数据传送到welcome页面,其实它只是一个request。
使用场景:在login页面填写的userName和password,在后台的action中验证处理以后,如果正确,页面将跳转到list页面或者其他的页面,但是我们需要login页面上的userName这个信息,所以就可以使用dispatcher这个属性。
**如果写成<result name="welcome" >/welcome.jsp</result>这样,那么这个result默认type=“dispatcher”。
所以很多时候如果你不写type=“dispatcher”时也感觉值从A页面传到了welcome页面,原因就是dispatcher是result的
默认值。
2.redirecter
<result name="welcome" type="redirecter">/welcome.jsp</result>
如果在A页面填写数据,通过action处理以后,到struts.xml的配置文件中,使用redirecter,
那么A页面中填写的数据在welcome页面中是取不到的。
3.chain
<action name="action2" class="com.struts.Action1">
<result name="toSecond" type="chain">action2</result>
</action>
<action name="action2" class="com.struts.Action2">
<result name="toWelcome" type="dispatcher">/welcome.jsp</result>
</action>
从页面A请求道action1中,做以相关的处理,处理完后跳转到action2中,然后在action2中处理相关的业务,然后再次跳转到welcome页面上。
为什么要这样写,目的就是为了将A页面上填写的相关的值可以在welcome页面上输出。
chain在这里的作用,我个人理解就是为了让从A页面上的request延续到action2中,
这样就不会重新发起一个request,所以A页面上的数据也就不会丢失,从而达到传值的目的。
result还有几种值类型,不常用,就不说了。
看看怎也在welcome.jsp上取login.jsp上的值。
login.jsp
<input type="text" name="account">
action.java
private String account;
getter/setter menthod ;
welcome.jsp
第一种取值方式:
<s:property value="account">
第种取值方式:
${account}
- struts2中XML配置中result的值
- Struts2中Result的配置
- [Struts2]struts.xml中result的path
- Struts2中struts.xml配置文件,result配置详解
- 一个Struts2的struts.xml中配置JSON类型RESULT的例子
- struts2 中配置result 中chain、redirect、redirectaction的区别
- struts2中struts.xml 的result 和param
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- struts2.xml 中result type属性说明
- Linux下软件的安装与卸载
- 高级I/O
- 面试_单链表操作试题_汇总
- curl实现apns
- Java的国际化(i18n)
- struts2中XML配置中result的值
- 树链剖分模板
- 第八周 项目一(3):实现复数类中的运算符重载(扩充类)
- [Matlab] 使用GPU进行滤波运算
- Sort Colors
- python2.7和python3.4网络编程处理二进制数据区别
- 2015.4.22.20.46_ecilipse_8.30_Eclipse 10个最有用的快捷键_0.01
- Problem 37—Truncatable primes
- 黑马程序员—异常小知识点整理