struts2的值栈存入和获取

来源:互联网 发布:商标r和tm的区别 知乎 编辑:程序博客网 时间:2024/06/08 17:36

一、获得值栈的方式:

1.ServletActionContext.getContext().getValueStack();

2.ActionContext.getContext().getValueStack();


二、值栈的使用

1. set键值对存入:

ServletActionContext.getContext().getValueStack().set("c", "cc");

取出:

  <s:property value="c" /><br/>

2.    push存入map栈顶:

ActionContext.getContext().getValueStack().pop();
ActionContext.getContext().getValueStack().push("bb");

取出:

  <s:property value="[0].top" /><br/>

3. 设置getXxx()方法:

private String name;
public String get
Name(){
  return name;
}

public String execute(){
name = "dd";
return "success";
}

取出:

 <s:property value="name" />


阅读全文
0 0
原创粉丝点击