如何使用struts在下拉列表中显示从JSP数据库中获取的数据?我已经使用城市的数组列表完成了下拉列表的代码,但发生了错误。
HTTP Status 500 - type Exception report message description
The server encountered an internal error () that prevented it from fulfilling this request.
exception org.apache.jasper.JasperException: tag 'select', field 'list', name
'location': The requested list key '%{city}' could not be resolved
as a collection/array/map/enumeration/iterator type.
我已经为城市列表做了这个代码如下:
JAVA代码
public class Event extends ActionSupport{
private String description;
public List<String> city;
public List<String> getCity() {
return city;
}
public void setCity(List<String> city) {
this.city = city;
}
public String execute() throws Exception{
String url = "jdbc:mysql://localhost:20976";
String dbName = "chetan";
String driverName = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root121";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url + dbName, user,pass);
stmt = con.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
rs = stmt.executeQuery("select * from City");
while (rs.next()) {
city.add(rs.getString("Location"));
}
return SUCCESS;
}
城市的 JSP 代码
<s:select name="location" label="Location" headerValue="Select City" list="city" />
<s:submit value="Submit" method="execute" key="submit" align="center" />