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>