1

以下Treemap是我传递的数据库中的所有值

Map<String, String> treeMap = new TreeMap<String, String>(map);
Iterator mapIterator = mapSet.iterator();
while (mapIterator.hasNext()) {
  Map.Entry mapEntry = (Map.Entry) mapIterator.next();
  String keyValue = (String) mapEntry.getKey();
  String value = (String) mapEntry.getValue();
  System.out.println("Key : " + keyValue + "= Value : " + value);
}
request.setAttribute("airline_name", treeMap);

在 JSP 页面中:

<html:select property="airline_name_value"  styleId  = "tempId" > 
  <html:options collection="airline_name" property="key" labelProperty="key" />  
</html:select>  

ActionForm

private String airline_name;
public String getAirline_name() {
return airline_name;
}
public void setAirline_name(String airline_name) {
this.airline_name = airline_name;
}

错误:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean under name airline_name

有没有其他方法可以使用html:options收藏标签?

4

1 回答 1

1

还有另一种不使用html:options而是使用的方法html:optionsCollection

<html:optionsCollection property="airlines" label="value" value="key" />

要使其正常工作,您应该在表单中映射属性

private Map<String, String> airlines;

public Map<String, String> getAirlines() {
  return airlines;
}

public void setAirlines(Map<String, String> airlines) {
  this.airlines = airlines;
}

在行动中

form.setAirlines(treeMap); 
于 2013-09-23T08:56:25.500 回答