如何在 Struts 1.3 中验证 html:options 集合?

问题描述 投票:0回答: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>
集合标签吗?

java html jsp struts struts-1
1个回答
3
投票

还有另一种方法,不使用

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); 
© www.soinside.com 2019 - 2024. All rights reserved.