我想在进入系统首页的时候就对数据库进行查询,然后讲要查询的数据以下拉里表的形式放在页面上
Action代码如下:
private List storesInfoList = new ArrayList();
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
// log.info("----------UserStoresAction Action-----------");
UserStoresService userStoresService = (UserStoresService) this
.getActionService(request,
ServiceNameConstants.USER_STORES_SERVICE);
this.setStoresInfoList(userStoresService.selectUserStores());
request.setAttribute("store", storesInfoList);
return SUCCESS;
}
// -----------------getter and setter方法------------
public List<UserStoresInfo> getStoresInfoList() {
return storesInfoList;
}
public void setStoresInfoList(List<UserStoresInfo> storesInfoList) {
this.storesInfoList = storesInfoList;
}
JSP代码如下:
/s:action
可是运行就报错,提示严重: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'UserStoresInfo.name': The requested list key 'storesInfoList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
哪位高手能帮我解决一下啊~~~
[b]问题补充:[/b]
我在Action把list全部替换成了iterator,结果还是提示那个错误,我感觉值没有传过去
既然是值没有传过去 ,那就去看看action里面的值是否存在,你使用的ognl表达式是否正确即可!
按照报错的信息来看 说你的storesInfoList不能作为iterator类型。
首先确定一下在页面是否storesInfoList是想象中的值,用来循环下看里面的值是预期的吗?
然后在补充问题,我再来!
使用<s:action 标签的方式访问ACTION,后面取值时,应该要加#号,<s:select list="#storesInfoList" ...