我无法在jstl中对象的arraylist上运行循环。这是描述我的对象的代码:
public class Target implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private String login;
private String title;
private String date;
private String description;
private String status;
public Target() {}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
这是JSP页面的代码,我尝试在其中打印数组的内容:
<%
if (session.getAttribute("user") == null){
response.sendRedirect("/Organaizer/");
return;
}
User user = (User) session.getAttribute("user");
request.setAttribute("targets", user.getTargets());
%>
<c:forEach items="${targets}" var="current">
<p>${current.title}</p>
<p>${current.login}</p>
</c:forEach>
不幸的是,这种实现不起作用。数据是有序的,如果你在scriptlet中处理数组,那么一切正常。我的错是什么?
答案 0 :(得分:0)
就像
一样<c:forEach items="${user.targets}" var="current">
<p>${current.title}</p>
<p>${current.login}</p>
</c:forEach
摆脱下面的
User user = (User) session.getAttribute("user");
request.setAttribute("targets", user.getTargets());
答案 1 :(得分:0)
我认为您所犯的错误不是导入核心标记库。