Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何迭代提供的;项目-将包含JSON数据的字符串显示到表(jsp)_Jsp_Foreach_Jstl - Fatal编程技术网

如何迭代提供的;项目-将包含JSON数据的字符串显示到表(jsp)

如何迭代提供的;项目-将包含JSON数据的字符串显示到表(jsp),jsp,foreach,jstl,Jsp,Foreach,Jstl,这就是我得到的错误: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach> 解释 在我的客户机中,我以字符串的形式从数据库表接收JSON数据。 如果我打印出我得到的字符串: [{"note_id":1,"title":"Homework","text":"Math ex. 15, 16, 17.","color":"Yellow"

这就是我得到的错误:

javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
解释

在我的客户机中,我以字符串的形式从数据库表接收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);

您应该从“note all”中删除“-”。

您不能在Java标识符中使用连字符字符。您可以使用${pp.note_id}访问id,因为id的私有名称是node_id。
<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>
@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;
    }

}