Hello to all of you, I using JQuery Data Table to display data but i getting JSON formatting error when post data back from server to client.
JSP
Servlet
JSP
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $("#ticketList").dataTable({ "bProcessing" : true, // Enable processing indicator "bServerSide" : true, // Configure data option - server or client // Send XHR request to server "sServerMethod": "POST", // GET or POST "bSort" : true, // Enable sorting "bFilter" : false, "bAutoWidth" : true, "sPaginationType" : "full_numbers", // Paginate Type -> two_button (Previous && Next) // -> full_numbers (First, Previous, 1, 2, Next, Last) "bLengthChange" : true, "iDisplayLength" : 10, "sAjaxSource" : "${context}/app.view?tn=Ticket.SearchTicket", // Override $.getJson() get data from server /*"fnServerData": function(sSource, aoData, fnCallback) { $.ajax({ "dataType": 'json', "type": "GET", // GET or POST to server for getting data "url": sSource, "data": aoData, "success": fnCallback, "error": function(jqXHR, textStatus, errorThrown) { console.log(txtStatus, errorThrown); // use alert() if you prefer } }); }, */ "aoColumns": [ //mData mDataProp {"mData": "id"}, {"mData": "category"}, {"mDataP": "status"}, {"mData": "assignee"}, {"mData": "urgency"}, {"mData": "action"} ] }); }); </script> <div class="clear" id="content"> <div class="box"> <em>Search Ticket </em> <div class="data"> <div class="fb clear"> <form id="searchTicketForm" name="searchTicketForm" action="${context}/app.view?tn=Ticket.SearchTicket" method="POST"> <fieldset> <div class="field"> <label>Ticket Id:</label> <input type="text" id="id" name="id"></input> </div> <div class="field"> <label>Category:</label> <select id="category" name="category"> <option value="account">Account</option> <option value="invoice" selected="selected">Invoice</option> <option value="rates">Rates</option> <option value="">No category</option> </select> </div> <div class="field"> <label>Urgency:</label> <select id="urgency" name="urgency"> <option value="high">High</option> <option value="medium" selected="selected">Medium</option> <option value="low">Low</option> <option value="">No urgency</option> </select> </div> <div class="field"> <label>Status:</label> <select id="status" name="status"> <option value="unassigned" selected="selected">Unassigned</option> <option value="in_progress">In Progress</option> <option value="solved">Solved</option> <option value="">No Status</option> </select> </div> <div class="clear"></div> <div id="error" class="field"></div> <br /> <div class="field"> <button class="dark" id="searchBtn" type="submit" name="search">Search Ticket</button> </div> </fieldset> </form> </div> </div> <div class="data"> <div id="ticketList_wrapper" class="dataTables_wrapper"> <c:if test="${not empty tableView}"> <div id="ticketList_length" class="dataTables_wrapper"> <!-- Show <select name="ticketList_length"> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> </select> entries --> </div> <!-- <form name="searchUserForm" action="${context}/app.view?tn=Ticket.SearchTicket" method="POST"> --> <table id="ticketList" class="display" cellspacing="0" cellpadding="0" border="0"> <thead> <tr> <th class="sorting"><b>Ticket ID</b></th> <th class="sorting_disabled"><b>Category</b></th> <th class="sorting_disabled"><b>Urgency</b></th> <th class="sorting_disabled"><b>Status</b></th> <th class="sorting_disabled"><b>Assignee</b></th> <th class="sorting_disabled"><b>Action</b></th> </tr> </thead> <tbody> <tr> <td colspan="5" class="dataTables_empty" align="center">Loading data from server</td> </tr> </tbody> </table> <!-- </form> --> </c:if> </div> </div> </div> </div>
Servlet
@Override public TaskResponse execute(HttpServletRequest request, HttpServletResponse response) throws WebTaskException { String sEcho = null; String sSearch = null; HttpSession session = request.getSession(); if (session == null) { throw new WebTaskException("Unauthorized Access"); } sEcho = request.getParameter("sEcho"); sSearch = request.getParameter("sSearch"); // Get page number -> Pagination -> XHR request if (sEcho != null) { Integer id = null; String categoryStr = request.getParameter("category"); String urgencyStr = request.getParameter("urgency"); String statusStr = request.getParameter("status"); int fetchRowSize = 100; int currentRow = 0; if (request.getParameter("iDisplayLength") != null) { fetchRowSize = Integer.parseInt(request.getParameter("iDisplayLength")); logger.log(Level.INFO, "Fetch Row Size " + fetchRowSize); } if (request.getParameter("iDisplayStart") != null) { currentRow = Integer.parseInt(request.getParameter("iDisplayStart")); logger.log(Level.INFO, "Current Row " + currentRow); } Ticket ticket = new Ticket(); List<Ticket> ticketList = new ArrayList<Ticket>(); if (request.getParameter("id") != null && request.getParameter("id") != "") { id = Integer.parseInt(request.getParameter("id")); ticket.setId(id.intValue()); } else { ticket.setId(-1); } if (this.category.get(categoryStr) != null) { ticket.setCategory(this.category.get(categoryStr).intValue()); } else { ticket.setCategory(-1); } if (this.urgency.get(urgencyStr) != null) { ticket.setUrgency(this.urgency.get(urgencyStr).intValue()); } else { ticket.setUrgency(-1); } if (this.status.get(statusStr) != null) { ticket.setStatus(this.status.get(statusStr).intValue()); } else { ticket.setStatus(-1); } ticketList = dao.findTicket(ticket, fetchRowSize, currentRow); JSONObject jsonObject = convertObject(ticketList); logger.log(Level.INFO, "Json String " + jsonObject.toString()); // taskResponse.setResponseType(ResponseType.JSON); taskResponse.setResponseText(jsonObject.toString()); logger.log(Level.INFO, "searchTicket POST XHR Request called"); /* MySql Pagination Test */ /*ticketList = dao.getAllTickets(id); for (Ticket t: ticketList) { logger.log(Level.INFO, String.valueOf(t.getId())); }*/ } else { request.setAttribute("tableView", "tableView"); } logger.log(Level.INFO, "searchTicket GET called" + String.valueOf(++callTime)); //taskResponse.addForwardTask(VBossProperties.getInstance(), "admin.ViewDefinePrivilege"); return taskResponse; }I had tried debug with firebug which found nothing and check the Json string using JSONINT and it say it is a valid json. What is the reason that cause this error? Please help. Thanks.