我正在尝试使用Java servlet创建对象的数组列表。然后,我需要将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;
}
}
我有arraylist和地图
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页面中的所有元素。