使用 Struts2,我必须展示类似
<select>
<option value="1>India</option>
<option value="2">US</option>
<option value="3">Mexico</option>
</select>
现在“1,2,3...”和“India, US, Mexico,...”这两个值都将通过 JDBC 连接从数据库中获取。我该怎么做?
如果你有这个课程:
class Country {
private String id;
private String name;
...
}
然后使用 JDBC恢复Country
数据库中的所有对象:
List<Country> countries = CountryDAO.getAllCountries();
<s:select>
您可以在带有标签的 jsp 中呈现此列表。
class Action extends ActionSupport {
private List<Country> countries;
...
public List<Country> getCountries() {...}
}
<s:select label="Pets"
list="countries"
listKey="id"
listValue="name"/>