Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <em>actual</em> problem is that you don't know how to process the JSON string in the client side. I strongly suggest to use <a href="http://jquery.com" rel="nofollow noreferrer">jQuery</a> for this since this simplifies DOM manipulation a lot. I suggest to go through <a href="http://docs.jquery.com/Tutorials" rel="nofollow noreferrer">their tutorials</a> or go get a <a href="http://rads.stackoverflow.com/amzn/click/1933988355" rel="nofollow noreferrer">decent book</a> on the subject.</p> <p>For the jQuery + JSON + Servlet + HTML table mix, I've posted similar answers before <a href="https://stackoverflow.com/questions/2203269/loading-alternative-content-via-tabs-and-jquery-and-jsp/2203376#2203376">here</a> and <a href="https://stackoverflow.com/questions/1900711/handling-servlet-output-in-ajax/1900796#1900796">here</a> with code examples how to populate a table with help of <a href="http://code.google.com/p/google-gson/" rel="nofollow noreferrer">Google Gson</a> and a Servlet, you may find it useful. I'll copypaste from one of them.</p> <p>Here are the Servlet and the Javabean:</p> <pre><code>public class JsonServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List&lt;Data&gt; list = dataDAO.list(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(new Gson().toJson(list)); } } public class Data { private Long id; private String name; private Integer value; // Add/generate getters/setters. } </code></pre> <p>The <code>JsonServlet</code> (you may name it whatever you want, this is just a basic example) should be mapped in <code>web.xml</code> on a known <code>url-pattern</code>, let's use <code>/json</code> in this example. The class <code>Data</code> just represents one row of your HTML table (and the database table).</p> <p>Now, here's how you can load a table with help of <a href="https://stackoverflow.com/questions/1900711/handling-servlet-output-in-ajax/1900796#1900796">jQuery.getJSON</a>:</p> <pre><code>$.getJSON("http://example.com/json", function(list) { var table = $('#tableid'); $.each(list, function(index, data) { $('&lt;tr&gt;').appendTo(table) .append($('&lt;td&gt;').text(data.id)) .append($('&lt;td&gt;').text(data.name)) .append($('&lt;td&gt;').text(data.value)); }); }); </code></pre> <p>The <code>tableid</code> of course denotes the <code>id</code>of the HTML <code>&lt;table&gt;</code> element in question.</p> <pre><code>&lt;table id="tableId"&gt;&lt;/table&gt; </code></pre> <p>That should be it. After all it's fairly simple, believe me. Good luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload