如何在Struts 1.3中使用hild:选项集合?

时间:2013-09-23 07:37:17

标签: java html jsp struts struts-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收藏代码吗?

1 个答案:

答案 0 :(得分: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);