struts2笔记(续五)

带参数的结果集

 

结论:一次request有且只有一个值栈。所以在服务器端action之间互相forward的时候,可以共享参数,所以在服务器端跳转的时候不需要传递参数,但是在客户端跳转的时候需要传递相应的参数。

 

Struts.xml:

<action name="user" class="com.oristand.actions.UserAction">

           <result type="redirect">/success.jsp?t=${type}</result>

       </action>

 

UserAction.java:

package com.oristand.actions;

 

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;

    }

    @Override

    public String execute() throws Exception {

       return SUCCESS;

    }

 

}

Success.jsp:

  from valueStack:<s:property value="t"/><br>//这里因为重定向的是jsp页面,而不是Action,所以不会产生value stack,所以这的值就为空

  

   from applicationContext: <s:property value="#parameters.t"/>//

这里的值就不为空

   <s:debug></s:debug>

 

 

访问属性的三种方式:

第一种:

<result type="redirect">/success.jsp?t=${type}</result>//注意不是EL表达式

第二种:

<s:property value="t"/>//访问value stack中的值

第三种:

<s:property value="#parameters.t"/>//访问application中的值

    <s:property value="errors.name[1]"/>//<s:debug>中分为value Stack ContentsStack Content,对于value Stack Contents中的Propert Name,可以通过名字(例如error直接访问),对于Stack Content中的内容,则必须通过#来访问,如#request

    <s:debug></s:debug>//这个很重要,可以查看Action中的value stackaction中的error是一个map,数据结构的东西还是很重要!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值