我想填充 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)