2017-04-13 17 views
0

私はどこで検索しましたが、必要なヘルプが見つかりません。jspテーブルのJsonの文字列を表示する方法

私のサーブレットでJSONデータを含むStringを受け取りました。これらのデータは、データベースから行であり、これを含んでいます。

[{"note_id":1,"title":"Homework","text":"Math ex. 15, 16, 17.","color":"Yellow","datetime":""}] 

私の問題は、私はJSTLを使用してHTMLテーブルの上にこれらのデータを表示することができないんだということです。

これは私が得るものです: enter image description here

(私はストレスを取得していますし、この問題を解決する方法を見つけ出すことはできません)。

サーブレットコード(POSTメソッド):

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    . 
    . 
    . 
    String output = resp.getEntity(String.class); 
    System.out.println("* JSON string contains: * " + output); //prints the string with json data successfully 

    ObjectMapper objectMapper = new ObjectMapper(); 
    TypeReference<ArrayList<Note>> mapType = new TypeReference<ArrayList<Note>>() {}; 
    ArrayList<Note> jsonToList = objectMapper.readValue(output, mapType); 

    request.setAttribute("allNotesOfUser", jsonToList); 

    RequestDispatcher rd = request.getRequestDispatcher("/Notes.jsp"); 
    rd.forward(request, response); 
} 

JSPコード(ちょうどテーブル部):

<table class="table table-striped"> 
     <thead> 
      <tr> 
       <th> Id </th> 
       <th> Title </th> 
       <th> Text </th> 
       <th> Color </th> 
       <th> Date/Time </th> 
      </tr> 
     </thead> 

     <tbody> 
     <c:forEach items="${allNotesOfUser}" var="pp"> 
       <tr> 
        <td><${pp.note_id}</td> 
        <td><${pp.title}</td> 
        <td><${pp.text}</td> 
        <td><${pp.color}</td> 
        <td><${pp.datetime}</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; 
    } 

} 

答えて

0

あなたが送ることができる簡単な方法Entity to JSPページに注意して印刷してください。また、あなたはJSONオブジェクトを使用することができますBTSのBSTの方法は、Javaスクリプトを使用する必要があります。この問題を解決するにはcom.google.gson.JSONObjectを使用することもできます。

1

私は理由を知りませんが、それはこのように見えたので、私は、私のJSPコードで<c:out value="" />を挿入しようとした。だから今、それが働いている

<c:forEach items="${allNotesOfUser}" var="pp"> 
       <tr> 
        <td><c:out value="${pp.note_id}" /></td> 
        <td><c:out value="${pp.title}" /></td> 
        <td><c:out value="${pp.text}" /></td> 
        <td><c:out value="${pp.color}" /></td> 
        <td><c:out value="${pp.datetime}" /></td> 
       </tr> 
     </c:forEach> 

enter image description here

をここでは、リンクですc:out

のいくつかの参考のために

+0

(今私はちょうど続けるだろうとTTにどこか泣いXDを立ち往生) jsonの構造が不明な場合はnyの考えですか? – CodeHunter

関連する問題