我想在其中填充arrayList类型的catList对象 使用key = catId选择框 和value = catName
public class GamesAction extends ActionSupport {
private ArrayList catList;
public String populate() {
GamesCategoryBusiness gcb = new GamesCategoryBusiness();
Map data = gcb.fetchAll();//fetching games category from database
String status = (String) data.get("status");
if (status.equalsIgnoreCase("success")) {
setCatList((ArrayList) data.get("gameCatList"));
return "POPULATE";
} else {
addActionError("Not able to fetch Game categories");
return INPUT;
}
public ArrayList getCatList() {
return catList;
}
public void setCatList(ArrayList catList) {
this.catList = catList;
}
}
另一个班级
public class GamesCategoryAction extends ActionSupport {
private long catId;
private String catName;
public long getCatId() {
return catId;
}
public void setCatId(long catId) {
this.catId = catId;
}
public String getCatName() {
return catName;
}
public void setCatName(String catName) {
this.catName = catName;
}
在struts.xml中
<action name="gameCatAdded" class="GamesCategoryAction"
method="addCategory">
<result name="POPULATE">/allCategory.jsp</result>
<result name="success">/allCategory.jsp</result>
<result name="input">/addCategory.jsp</result>
<result name="login">/login.jsp</result>
</action>
在Jsp中
<s:select list="catList"
listKey="catId"
listValue="catName"
name="gamesCategoryId"
label="Category"
labelposition="top"/>
在jsp页面中显示以下错误 例外
org.apache.jasper.JasperException: tag 'select', field 'list', name 'gamesCategoryId': The requested list key 'catList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
答案 0 :(得分:0)
在动作类中尝试:ArrayList<Catalog> catList
。如果您从未声明过对象类型,那么您的对象类型是未知的。 (假设您有一个名为Catalog
的域类,其中包含catId
和catName
)