我正在尝试用JavaServlet创建一个对象的arraylist。然后我需要将arraylist发送到html页面。我有一个包含所有方法的类:
public class Internship {
private String city;
private int hours;
private String time;
public Internship(String city, int hours, String time) {
this.city = city;
this.hours = hours;
this.time = time;
}
public String getcity() {
return city;
}
public void setcity(String city) {
this.city = city;
}
public int gethours() {
return hours;
}
public void sethours(int hours) {
this.hours = hours;
}
public String gettime() {
return time;
}
public void settime(String time) {
this.time = time;
}
}
我有数组列表和Map
Map<String, Object> root = new HashMap();
ps = db.prepareStatement("select * from internship where id=?");
ps.setInt(1, Integer.parseInt(userId));
rs = ps.executeQuery();
String city = "";
int hours;
String time = "";
ArrayList<Internship> list = new ArrayList();
while (rs.next()) {
list.add(new Internship(rs.getString("city"), rs.getInt("hours"), rs.getString("time ")));
}
root.put("list", list);
在html方面,我有
<select id="list1" name="list1">
<c:forEach items="${list}" var="list1">
<option value="${list1.key}">
${list1.value}
</option>
</c:forEach>
</select>
问题是,在html部分,我可以看到仅选择每个元素的列表,例如:
<h3>Where</h3> <p>${list[1]}</p>
但是我想迭代列表并显示html页面中的所有元素。
暂无答案!
目前还没有任何答案,快来回答吧!