struts2 <s:select>标签
Servlet.service()forservletjspthrewexceptiontag'select',field'list',name'user.departm...
Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'user.department.departmentcode': The requested list key '#request.list_department' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
biz层
public List findDepartment() {
String hql = "from Department ";
List list = this.getDao().find(hql);
return list;
}
action 层
public String findDepartment(){
List list = this.biz.findDepartment();
ServletActionContext.getRequest().setAttribute("list_department", list);
return "";
}
private Department department;
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
jsp
<s:action name="user!findDepartment"></s:action>
<s:select theme="simple" name="user.department.departmentcode" headerKey="-1" headerValue="全部"
list="#request.list_department" listKey="department.departmentcode" listValue="department.departmentname">
</s:select> 展开
tag 'select', field 'list', name 'user.department.departmentcode': The requested list key '#request.list_department' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
biz层
public List findDepartment() {
String hql = "from Department ";
List list = this.getDao().find(hql);
return list;
}
action 层
public String findDepartment(){
List list = this.biz.findDepartment();
ServletActionContext.getRequest().setAttribute("list_department", list);
return "";
}
private Department department;
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
jsp
<s:action name="user!findDepartment"></s:action>
<s:select theme="simple" name="user.department.departmentcode" headerKey="-1" headerValue="全部"
list="#request.list_department" listKey="department.departmentcode" listValue="department.departmentname">
</s:select> 展开
4个回答
展开全部
jsp页面报错,#request.list_department不能作为一个集合访问。问题出在这一句吧:ServletActionContext.getRequest().setAttribute("list_department", list);这样设置,在页面取到的是一个字符串,可以先在后台转换为json,在jsp页面获取再反转一次即可。不过,简单点的做法是在action里设置一个类似集合的属性,把值赋给这个属性,然后直接调用这个属性即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
嗯 你可以试试listKey="departmentcode" listValue="departmentname" 前面不用department的 你要那个干什么呢啊
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看action list 有没有东西 ,,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么东西
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询