这是action。 查询的是一个用户,因为有外键,所以放在session中。 public String selectuser(){
ActionContext.getContext().getSession().put("all", iUserBiz.findAll());
System.out.println(iUserBiz.findAll().size());
return "user";
}
用
<s:iterator value="all" >
<tr>
<b><s:property value="#session.all.UId" /></b>
<b><s:property value="#s.UName"/></b>
<s:property value="%{session.all.UName}"/>
</td>
</tr>
</s:iterator>分别用了这几种方法取值,但都去不到。谁能告诉我怎么改啊。
ActionContext.getContext().getSession().put("all", iUserBiz.findAll());
System.out.println(iUserBiz.findAll().size());
return "user";
}
用
<s:iterator value="all" >
<tr>
<b><s:property value="#session.all.UId" /></b>
<b><s:property value="#s.UName"/></b>
<s:property value="%{session.all.UName}"/>
</td>
</tr>
</s:iterator>分别用了这几种方法取值,但都去不到。谁能告诉我怎么改啊。
<tr>
<td>
<s:property value="#s.UName"/>
</td>
</tr>
</s:iterator>
<tr>
<td>
<b><s:property value="#a.UId" /></b>
<b><s:property value="#a.UName"/></b>
</td>
</tr>
</s:iterator>
单个对象的话无需迭代el表达式写法${sessionScope.all.UId}(EL表达式不能用在struts标签中)
OGNL的写法<s:property value="#session.all.UId"/>
集合的话<s:iterator value="#session.all">
//EL和struts2标签都可以,struts2迭代的时候它会把每个元素放到栈顶
EL:${UId}
<s:property value="UId"/>
</s:iterator>其它属性同理
ActionContext.getContext().getSession()是个Map
ActionContext.getContext().getSession().put("all", iUserBiz.findAll());
System.out.println(ServletActionContext.getRequest().getSession().getAttribute("all")); 会输出什么?
struts标签里不能用EL。要用ognl,把%改为#