title: DataTables warning: table=userTable - Invalid JSON response?
body: <p>I use jQuery DataTables and get this warning message:</p>
  
  <blockquote>
    <p>DataTables warning: table=userTable - Invalid JSON response</p>
  </blockquote>
  
  <p>A servlet fetch users from MySQL which I want to display in a jQuery Datatable, but Ajax can't parse the JSON or the JSON is generated wrong in servlet?</p>
  
  <p>Servlet:</p>
  
  <pre><code>    List&lt;UserDTO&gt; users = this.service.getAllUser();
                  Gson gson = new Gson();
                  request.setAttribute("users", gson.toJson(users));
                  request.getRequestDispatcher("listAllUser.jsp").forward(request, response);
  </code></pre>
  
  <p>JSP:</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Registered Users&lt;/title&gt;
      &lt;script src="http://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
      &lt;script
          src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet"
          href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" /&gt;
      &lt;link rel="stylesheet"
          href="http://code.jquery.com/ui/1.11.4/themes/flick/jquery-ui.css"&gt;
      &lt;script&gt;
          $(document).ready(function() {
              $('#userTable').dataTable({
                  "processing" : true,
                  "serverSide" : true,
                  "ajax" : {
                      "url" : "ListAllUserServlet",
                      "type" : "POST"
                  },
                  "columns" : [ {
                      "data" : "id"
                  }, {
                      "data" : "userName"
                  }, {
                      "data" : "firstName"
                  }, {
                      "data" : "lastName"
                  }, {
                      "data" : "email"
                  }, {
                      "data" : "phone"
                  }, {
                      "data" : "location"
                  }, {
                      "data" : "password"
                  }, {
                      "data" : "gender"
                  }, {
                      "data" : "birthday"
                  } ]
              });
          });
      &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table id="userTable" class="display"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th colspan="10" id="userList"&gt;Users&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;User id&lt;/th&gt;
                      &lt;th&gt;User name&lt;/th&gt;
                      &lt;th&gt;First Name&lt;/th&gt;
                      &lt;th&gt;Last Name&lt;/th&gt;
                      &lt;th&gt;Email&lt;/th&gt;
                      &lt;th&gt;Phone&lt;/th&gt;
                      &lt;th&gt;Location&lt;/th&gt;
                      &lt;th&gt;Password&lt;/th&gt;
                      &lt;th&gt;Gender&lt;/th&gt;
                      &lt;th&gt;Birth date&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
  
              &lt;tfoot&gt;
                  &lt;tr&gt;
                      &lt;td colspan="10"&gt;&lt;a href="index.jsp" id="toIndex"&gt;Back&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tfoot&gt;
          &lt;/table&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>JSON generated by servlet:</p>
  
  <pre><code>[
      {
          "id": 1,
          "userName": "userName1",
          "firstName": "firstName1",
          "lastName": "lastName1",
          "email": "email1@gmail.com",
          "phone": "36202080085",
          "location": "location1",
          "password": "password1",
          "gender": "m",
          "birthday": "1-02-2015"
      }
  ]
  </code></pre>