Populate dataTable

Populate dataTable

Bilanga1976Bilanga1976 Posts: 1Questions: 1Answers: 0
edited October 2018 in Free community support

It is my first to use dataTable. Please

file1.jsp

<link rel="stylesheet" href="DataTables/jquery.dataTables.min.css"/>
<script type="text/javascript" src="DataTables/datatables.min.js"></script>
<script type="text/javascript" src="DataTables/jquery-3.3.1.js"></script>
<script type="text/javascript" src="DataTables/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        var oTable = $('#example').dataTable( {
            "processing": true,
            "ajax": {
                "url": "/Gestion_type_risque",
                "dataSrc": "demo",
                "type": "GET"
            }
        } );
    });
</script>

servlet2.java

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        
            
        List<AA> list_AbSce = new ArrayList<AA>();
        list_AbSce = DaoTypeRisque.getAllTypeRisque();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        resp.setContentType("application/json");
        String jsonArray = gson.toJson(list_AbSce);
        jsonArray = "{\"demo\":" + jsonArray + "}";
        System.out.println(jsonArray);
        resp.getWriter().print(jsonArray);      
        this.getServletContext().getRequestDispatcher(VUE).forward(req, resp);      
    }

At this level in console, i've information like this:

{"demo":[
  {
    "A": "data1",
    "B": "data2",
    "C": "data3",
    "D": "data4"
  },
  {
    "A": "data5",
    "B": "data6",
    "C": "data7",
    "D": "DATA8"
  }, and so on.

In web.xml file:

**<servlet>
<servlet-name>servlet2</servlet-name>
<servlet-class>servletPackage.servlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet2</servlet-name>
<url-pattern>/Gestion_type_risque</url-pattern>
</servlet-mapping>
**
But i've this error

Answers

This discussion has been closed.