ssh javaee中关于<s:select>标签访问数据库问题
老是报错Therequestedlistkey'categoryList'couldnotberesolvedasacollection/array/map/enumer...
老是报错
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="name" listValue="id" />
</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="name" listValue="id" />
</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
} 展开
2个回答
展开全部
<s:select id="Select" name="Select" list="%{mylist}" listValue="name" listKey="userID" value="%{#request.cid}"/>
value是默认选中的
value是默认选中的
更多追问追答
追问
改成这个么
还是报错
追答
改成value=""试试,你后台又没有传request.cid过来,应该是取不到的,我前面只是给你举个例子。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询