老是报错
The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
怀疑是类型转换的问题??主要代码如下
jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>添加新闻</title>
</head>
<body>
<s:form action="addNews" method="post">
<s:select list="categoryList" listKey="id" listValue="name" />
</s:form>
</body>
</html>action中
public class NewsAction
{
private News news;
private Category cat;
private NewsService newsService;
private CategoryService categoryService;
private List<Category> categoryList;
+get, set方法
public String add()
throws Exception
{
List<Category> list=new ArrayList<Category>();
list=categoryService.findAllCategory();
this.setCategoryList(list);
}
}Category bean类
public class Category {
private Integer id;
private String name;
private String code;
private java.util.Date createDate;
+get set
}
The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
怀疑是类型转换的问题??主要代码如下
jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>添加新闻</title>
</head>
<body>
<s:form action="addNews" method="post">
<s:select list="categoryList" listKey="id" listValue="name" />
</s:form>
</body>
</html>action中
public class NewsAction
{
private News news;
private Category cat;
private NewsService newsService;
private CategoryService categoryService;
private List<Category> categoryList;
+get, set方法
public String add()
throws Exception
{
List<Category> list=new ArrayList<Category>();
list=categoryService.findAllCategory();
this.setCategoryList(list);
}
}Category bean类
public class Category {
private Integer id;
private String name;
private String code;
private java.util.Date createDate;
+get set
}
解决方案 »
- 调用一个js不到,早来早拿分。
- Java如何实现时时监控数据库变动
- Hibernate 分页 dao里边如何获得总记录数
- 动态树型菜单java类设计
- 批处理中del *.* 如何才能不提示<y/n>??...
- 在JBuilderX+jboss4.0.2不能编译JSP??
- 谁能给我讲讲单点登录(SSO)的实现原理呀???
- 我是用JBuilder2005+JBoss+Oracle9i开发,我先装的Oracle,结果8080端口就被oracle占用了,那我的JBoss是用的那个端口啊?该如何去JBoss
- [请教]字符串压缩的问题:出错java.util.zip.ZipException: missing entry name
- Redis作为缓存框架的问题
- Struts2 s:radio 怎么显示默认的属性
- Struts2学习问题,求解
怎么用${}?action中定义了
private List<Category> categoryList;
+set get 方法
<result name="success">你的.jsp</result>
</action> ?
好像这个<s:form action="addNews" method="post">
里面写的action在提交的时候才有用,而你用的数据必须是addNews的执行结果,貌似使用的先后次序有问题啊
在页面上导入jstl标签库如
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>然后遍历集合
<c:forEach items="${categoryList}" var="p">
</c:forEach>
${p.count }
</c:forEach>
就这样一句话是知道你的是不是集合了,如果是集合的话应该有多条数据
p.count就是条数
"${categoryList}这里有警告
"items" does not support runtime expressions运行报错
According to TLD or attribute directive in tag file, attribute items does not accept any expressions] with root cause
你是没有导入jstl标签库巴
先导入<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
然后在
<c:forEach items="${list}" varStatus="p">
${p.count }
</c:forEach>
就知道你的集合能不能取到值了