struts2的值栈结构

来源:互联网 发布:淘宝店怎么刷销量 编辑:程序博客网 时间:2024/05/21 22:18


public String getValue()
{
this.username = "tomcat";
this.password = "123456";
this.nickname = "tomcat nick";
ActionContext.getContext().put("user", "this is a user");
ServletActionContext.getRequest().setAttribute("pd", "this is a password");
return "value";

}


以上是三种传值方式



下面是EL表达式与OGNL表达式的显示值的试。

el:{usrename}<br/>
el:{password}<br/>
el:{nickname}<br/>
el:{user}<br/>
el:{pd}<br/>




struts:<s:property value="username"/><br/>
struts:<s:property value="password"/><br/>
struts:<s:property value="nickname"/><br/>
struts:<s:property value="user"/><br/>
struts:<s:property value="#request.pd"/><br/>



Struts2的值栈结构,有两种情况,一种是Map结构,一种是List结构,

也就是说ValueStack分为Map和List,而这个Map也就是ActionContext,而List就是CompRoot,是两种不同的数据结构存储方式。

获取Map当中的数据,与List中的数据有的时候都需要加这个“#”号,如果是娶List的第一个元素,第一个元素直接暴露出来,可以直接获取栈顶元素的属性。

Map结构
// Ognl.getValue(expression, context, root);
// System.out.println(Ognl.getValue("sname", context, students));
// System.out.println(Ognl.getValue("rname",context, role));
// System.out.println(Ognl.getValue("#roles.rname",context, students));
// System.out.println(Ognl.getValue("roles.rname",context, context));
System.out.println(Ognl.getValue("#root.sname",context, students));

List结构

System.out.println(Ognl.getValue("get(0).rname",lists));
System.out.println(Ognl.getValue("#root[2].sname",lists));





0 0
原创粉丝点击