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中的值!
我的問題是這是正確的行爲?