简体   繁体   中英

jquery datatables is not loading table data

Problem:

I am trying to represent data in a tabular format,this data is to be retrieved from a database My table data is not getting loaded even after I hard code values.

Case:

I am retrieving data from a database and just displaying the data on a UI using Jquery datatables. 1.I have created a Java-bean for retrieving the data 2.Created a servlet to retrieve data from a database 3.I have created a jsp page to display the output

The code is as follows:

BuyerViewServlet.java

@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    processRequest(request, response);

    processRequest(request, response);

    PrintWriter out = response.getWriter();
    BuyerView buyerview = getBuyerInfo();
    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    String json = gson.toJson(buyerview);

    response.setContentType("application/json");

    out.print(json);
    System.out.print(json.trim());

    out.close();

}

   //sets the JavaBean
   public BuyerView getBuyerInfo() {

    BuyerView info = new BuyerView();

    //info.setConsID(45);
    info.setEmailUser("james@kngs.com");

    return info;

  }//END OF getInfo()


///jsp
<table id="consumer_information" class="display" cellspacing="0" width="100%">
<thead>
    <tr>

        <th>Name of Customer</th>
        <th>Email</th>


    </tr>
</thead>
 <tbody>          
 </tbody>

 <script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-XXXXX-X', 'auto');
  ga('send', 'pageview');
</script>
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.1  /js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" class="init">
    $(document).ready(function() {
    $('#consumer_information').dataTable( {
           "sServerMethod ":"POST" ,
         "sPaginationType" : "full_numbers",
            "bProcessing" : false,
            "bServerSide" : false,
            "sAjaxSource" : "./BuyerViewE",
            "bJQueryUI" : true,
            "aoColumns" : [
        { "mData": "Name of Company" },
        { "mData": "Email" }

    ]
   } ); 
     } );


</script>

You haven't described exactly what type of error, if any, you are currently getting. However, just looking at your code, it seems that the src attribute for one of your script tags is incorrect.

You have:

<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.1  /js/jquery.dataTables.js"></script>

Try removing the space between '1.10.1' and the '/js'. So basically, change your script tag to the following:

<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.1/js/jquery.dataTables.js"></script>

See if this change fixes your problem. If there are other issues then please provide the specific results/errors you are seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM