public class Demo7 {
/**
*
* 值栈的使用
*
*/
public static void main1(String[] args) {
// 栈:表示一个先进后出的数据结构
ActionContext ctx=ActionContext.getContext();
ValueStack vs = ctx.getValueStack();
// push方法把项压入栈顶(压栈)
vs.push(new Employee("zs", 22));
vs.push(new Employee("ls", 22));
vs.push(new Employee("ww", 22));
// pop方法移除栈顶对象并作为此函数的值返回该对象(弹栈pop)
Employee e = (Employee) vs.pop();
System.out.println(e.getName());
e = (Employee) vs.pop();
System.out.println(e.getName());
e = (Employee) vs.pop();
System.out.println(e.getName());
}
/**
* 此例用于模拟struts2的值栈计算过程
*
* @param args
*/
public static void main(String[] args) {
//拿到struts上下文
ActionContext ctx=ActionContext.getContext();
//拿到值栈
ValueStack vs = ctx.getValueStack();
vs.push(new Employee("张雇员", 2000));// 1
vs.push(new Student("小明同学", "s001"));// 0
System.out.println(vs.findValue("name"));
System.out.println(vs.findValue("salary2"));
System.out.println(vs.findValue("salary"));
//小明同学,null,2000
ActionContext ac = ActionContext.getContext();
}
public String execute() {
main1(null);
System.out.println("------------------------------");
main(null);
return null;
}
ognl集成到struts上下文里
猜你喜欢
转载自blog.csdn.net/li_2580/article/details/83994910
今日推荐
周排行