封装对象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>
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>
本文详细介绍了如何在Struts2框架中使用值栈进行数据传递,包括字符串、对象及集合的存取方法,并提供了具体的Action与JSP示例。
963

被折叠的 条评论
为什么被折叠?



