关于struts2 select标签的使用问题,请大家帮忙看看啦!感激不尽 用select标签时一直有这个问题,找了很多方法都不知道怎么解决, <s:select name="classid" list="#request.classArray" headerKey="0" headerValue="==请选择==" listKey="classid" listValue="classname" value="ClassId"> </s:select> 错误:tag 'select', field 'list', name 'classid': The requested list key '#request.classArray' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} 我也知道这可能是因为List属性中没有初值,因为把List中的值换成这样就能显示了: <s:select name="classid" list="#{0:'ooo',1:'aaa'}" headerKey="0" headerValue="==请选择==" listKey="classid" listValue="classname" value="ClassId"> </s:select> 但不是说list属性中没有初值是,加了headerKye,headerValue就可以了的么?? 这问题困扰很久了。请帮忙解决下。感激不尽啊!
classviewAction如下:希望大家能帮我看看怎么解决 public class ClassViewAction extends ActionSupport {
private static final long serialVersionUID = 1L; public String action; public String classid; @Override public String execute() throws Exception { Connection conn=DBConn.createDBConn(); String sql="select * from ClassTa"; Statement stclass=conn.createStatement(); ResultSet rsclass=stclass.executeQuery(sql); ArrayList<ClassTa> classArray=new ArrayList<ClassTa>(); while(rsclass.next()){ ClassTa classta=new ClassTa(); classta.setClassid(rsclass.getInt("classid")); classta.setClassname(rsclass.getString("classname")); classArray.add(classta); } Map request = (Map)ActionContext.getContext().get("request"); request.put("classArray", classArray); if(classid!=null&&classid.length()!=0){ sql="select * from student where classid="+classid; Statement state=conn.createStatement(); ResultSet rs=state.executeQuery(sql); ArrayList<Student> stuArray=new ArrayList<Student>(); while(rs.next()){ Student stu=new Student(); stu.setBedchamberId(rs.getInt("bedchamberId")); stu.setClassId(rs.getInt("classId")); stu.setMatriNo(rs.getString("matriNo")); stu.setPayAmount(rs.getFloat("payAmount")); stu.setPayOK(rs.getInt("payOK")); stu.setRegistDate(rs.getDate("registDate")); stu.setSpecialityId(rs.getInt("specialityId")); stu.setStudentId(rs.getLong("studentId")); stu.setStudentName(rs.getString("studentName")); stuArray.add(stu); } request.put("stuArray", stuArray); } DBConn.closeConn(conn); return SUCCESS; } public String getAction() { return action; } public void setAction(String action) { this.action = action; } public String getClassid() { return classid; } public void setClassid(String classid) { this.classid = classid; }
}
------解决方案-------------------- list="#request.classArray",你这样写有数据时能获取到从后台传过来的值? 我常用的方法是:在action中定义classArray类,然后生成它的get、set方法,在页面直接用list="classArray"就搞定了。 The requested list key '#request.classArray' could not be resolved as a collection
------解决方案--------------------