1

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("[email protected]");

    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>

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Ohh yeah, Sorry, this is the error, datatables.net/tn/1, which should tranlate to bad JSON format, Ive checked the logger and the JSON format is as follows,
{"name":"samwel","email":"[email protected]"}
@cliffjosiah I don't see anything wrong with the JSON you provided. Did you try making the change I suggested?
Yes I did, but there was no change, what I am trying to do now is to use JSP instead of ajax to retrieve the data

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.