1
public class UserAction{
private UserData user;
//getter, setter
public String Load() {
user = UserDao.getInstance().getItem(getUserContext().getId());
request.getSession().setAttribute("item", user);
return super.Load();
}
}
public class PropertyAction {
private List <PropertyData> propertyList;
//getter, setter
@Override
public String execute() throws Exception {
propertyList=PropertyDao.getInstance().getItems();
return "list";
}
}
的jsp:的java struts2的同时使用迭代器非常奇怪的行为
<s:iterator value="propertyList" var="item">
${item.name}
${item.thema}
${item.desc}
</s:iterator>
我想说明的Struts2的非常奇怪的行为。
- 我点击属性链接 - >然后运行PropertyAction.execute(),它显示在jsp上面。
- 我点击用户链接 - >然后运行UserAction.Load()
- 我点击资源链接 - >然后运行PropertyAction.execute()和错误已被证明“的UserData没有财产天马”。
我间谍发生了什么,我注意到我设置了名称为“item”的setAttribute。所以如果我在jsp的迭代器中使用var =“item”,它不会使用propertyList中的值,而是使用session中的值!
我的问题是这是正确的行为?