【发布时间】:2012-07-31 09:33:15
【问题描述】:
如何使用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" />
【问题讨论】:
-
你尝试了什么,你卡在哪里了?
-
我已经使用城市的数组列表完成了下拉列表的代码,但发生了错误。
-
请贴出错误信息的代码
-
HTTP 状态 500 - 类型异常报告消息描述 服务器遇到内部错误 () 阻止它完成此请求。异常 org.apache.jasper.JasperException:标记“选择”、字段“列表”、名称“位置”:请求的列表键“%{city}”无法解析为集合/数组/映射/枚举/迭代器类型.
-
和代码?