在action中将字符串、对象、list集合保存到值栈中,在jsp页面中获取的方法

来源:互联网 发布:淘宝卖东西侵权怎么办 编辑:程序博客网 时间:2024/05/19 13:19
封装对象User,属性有id,username,email等
1.1:在action中将字符串保存到值栈中
   1.1.1 获取值栈对象
         ValueStack stack = ActionContext.getContext().getValueStack();
   1.1.2 将字符串保存到值栈中
         stack.set("username","leo");
1.2:在jsp页面中获取值栈中的字符串
   1.2.1 <s:property value="username"/>

2.1:在action中将对象保存到值栈中
   2.1.1 获取值栈对象
         ValueStack stack = ActionContext.getContext().getValueStack();
   2.1.2 将对象保存到值栈中
         stack.set("user",user);
2.2:在jsp页面中获取值栈中保存的对象
   2.2.1 <s:property value="user.username" />

3.1:在action中将集合List保存到值栈中
   3.1.1 获取值栈对象
         ValueStack stack = ActionContext.getContext().getValueStack();
   3.1.2 将对象保存到值栈中
         stack.set("userList",list);
3.2:在jsp页面中获取值栈中保存的集合
   3.2.1 <s:iterator value="userList">
        <s:property value="id"/>
        <s:property value="username"/>
     </s:iterator>
   3.2.1 <s:iterator value="userList" var="user">
        <s:property value="#user.id"/>
        <s:property value="#user.username"/>
     </s:iterator>

0 0
原创粉丝点击