这是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>分别用了这几种方法取值,但都去不到。谁能告诉我怎么改啊。

解决方案 »

  1.   

    首先你要确认all是有值的。试试这样的。<s:iterator value="request.all" var="a">
      <tr>
       <td>
     <s:property value="#s.UName"/>   
     </td>
     </tr>
    </s:iterator>
      

  2.   

    变量错了,这样取值<s:property value="#a.UName"/> 
      

  3.   

    这个办法不行的,我在action中放在在session中了
      

  4.   

    <s:iterator value="#session.all"  var="a">
      <tr>
       <td>
           <b><s:property value="#a.UId" /></b>
                 
           <b><s:property value="#a.UName"/></b>
       
     </td>
     </tr>
    </s:iterator>
      

  5.   

    你这个session里面的all到底是一个集合还是单个对象啊
    单个对象的话无需迭代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>其它属性同理
      

  6.   


    ActionContext.getContext().getSession()是个Map
      

  7.   

    你确定session中有值吗?
    ActionContext.getContext().getSession().put("all", iUserBiz.findAll());    
    System.out.println(ServletActionContext.getRequest().getSession().getAttribute("all")); 会输出什么?
      

  8.   

    <s:property value="%{session.all.UName}"/>
    struts标签里不能用EL。要用ognl,把%改为#