我正在开发一个简单的struts应用程序.在我的JSP中,我有一个下拉列表框(使用s:select标签).我需要在action类中用arraylist值填充值.我怎样才能做到这一点?在structs.xml文件中需要进行哪些更改才能完成此操作?
JSP:
<s:select name="department" label="" list="departmentlist" headerKey="-1" headerValue="Select Department">
行动类:
private List<String> departmentlist = new ArrayList<String>();
public String xyz()
{
departmentlist.add("aaa");
departmentlist.add("bbb");
departmentlist.add("ccc");
departmentlist.add("ddd");
return "success";
}
解决方法:
错误
“The requested list key ‘departmentlist’ could not be resolved as a
collection/array/map/enumeration/iterator type. Example: people or
people.{name} – [unknown location] “
表示select标签无法将departmentlist解析为集合.它是一个OGNL表达式,它试图在值堆栈中找到departmentlist,如果找不到或包含null引用,则select标签会抱怨.渲染select标记时,请确保列表位于值堆栈中并进行初始化.请参见示例here.