老是报错
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
}

解决方案 »

  1.   

    试试用EL表达式${}看能不能获得到值了,感觉你这里是遍历集合的问题,不知道你的那个categoryList是不是一个集合
      

  2.   


    怎么用${}?action中定义了
    private List<Category> categoryList;
    +set get 方法
      

  3.   

    struts.xml的配置中有没有 <action name="addNews">
                                   <result name="success">你的.jsp</result>
                           </action>    ?
    好像这个<s:form action="addNews" method="post">
    里面写的action在提交的时候才有用,而你用的数据必须是addNews的执行结果,貌似使用的先后次序有问题啊
      

  4.   

    你应该用过才对呀,你现在都用struts2标签了,你不可能没有用过吧
    在页面上导入jstl标签库如
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>然后遍历集合
    <c:forEach items="${categoryList}" var="p">
    </c:forEach>
      

  5.   

    <c:forEach items="${list}" varStatus="p">
         ${p.count }
        </c:forEach>
    就这样一句话是知道你的是不是集合了,如果是集合的话应该有多条数据
    p.count就是条数
      

  6.   


    "${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
      

  7.   


    你是没有导入jstl标签库巴
    先导入<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    然后在
    <c:forEach items="${list}" varStatus="p">
      ${p.count }
      </c:forEach>
    就知道你的集合能不能取到值了