这是我得到的错误:
javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
解释
在我的客户端中,我以String的形式从数据库表中接收JSON数据。 如果我打印出我得到的字符串:
[{"note_id":1,"title":"Homework","text":"Math ex. 15, 16, 17.","color":"Yellow","datetime":"d"}]
我想在我的jsp文件中将此数据显示到表中,因此我将字符串转换为ArrayList:
ObjectMapper objectMapper = new ObjectMapper();
TypeReference<ArrayList<Note>> mapType = new TypeReference<ArrayList<Note>>() {};
ArrayList<Note> jsonToList = objectMapper.readValue(output, mapType);
request.setAttribute("note-all", jsonToList);
RequestDispatcher rd = request.getRequestDispatcher("/Notes.jsp");
rd.forward(request, response);
然后,当我尝试在JSP文件中的表中显示结果时,我在 forEach 循环中收到错误:
<table class="table table-striped">
<thead>
<tr>
<th> Id </th>
<th> Title </th>
<th> Text </th>
<th> Color </th>
<th> Date/Time </th>
<th> Actions </th> <!-- the table header for Actions -->
</tr>
</thead>
<tbody>
<c:forEach items="${note-all}" var="pp">
<tr>
<td><${pp.id}</td>
<td><${pp.title}</td>
<td><${pp.text}</td>
<td><${pp.color}</td>
<td><${pp.datetime}</td>
<!-- The final column is the Actions, which is a list of buttons,
that we can perfom on our User Entities. -->
<td>
<div class="btn-group">
<a href="@Url.Action("Edit", new {pp.id})" class="btn btn-xs btn-primary">
<i class="glyphicon glyphicon-edit"></i>
Edit
</a>
<a href="@Url.Action("Delete", new {pp.id})" class="btn btn-xs btn-danger" data-post="Are you sure tou want to delete @user.Username ?">
<i class="glyphicon glyphicon-remove"></i>
Delete
</a>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
这是我的Note课程:
@XmlRootElement
public class Note {
private int note_id;
private String title;
private String text;
private String color;
private String datetime;
public Note(int note_id, String title, String text, String color, String datetime){
this.note_id = note_id;
this.title = title;
this.text = text;
this.color = color;
this.datetime = datetime;
}
public Note(){
super();
}
public int getNote_id() {
return note_id;
}
public void setNote_id(int note_id) {
this.note_id = note_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getDatetime() {
return datetime;
}
public void setDatetime(String datetime) {
this.datetime = datetime;
}
}
答案 0 :(得分:0)
你应该删除&#34; - &#34;来自&#34; note-all&#34;。