Regarding Passing parameter to servlet in Datatable
Regarding Passing parameter to servlet in Datatable
rmani
Posts: 4Questions: 0Answers: 0
Hi do I pass parameter to a servlet and get the JSONArray to display it in Datatable, my code looks like the following. But currently it doesnt return any value, servlet doesn't recognise the do_action parameter I am passing it to, I am building JSONArray by check this parameter in the servlet. Any One throw some light on how this can be done.
[code]
JSP CODE:
$(document).ready(function() {
var oTable = $('#tableId').dataTable( {
"bprocessing": true,
"bServerSide": true,
"sAjaxSource": "/umResourceRequestController?do_action=listUsers",
"aoColumns": [
{ "mData": "appInstance" },
{ "mData": "usrId" },
{ "mData": "loginId" },
]
});
});
Servlet Code:
//List User
if ( do_action.equals("listUsers")){
ArrayList userlist = new RPUserDAO().getrpUserList(connection);
Gson gson = new Gson();
JsonElement element = gson.toJsonTree(userlist, new TypeToken() {}.getType());
JsonArray jsonArray = element.getAsJsonArray();
response.setContentType("application/json");
response.getWriter().print(jsonArray);
[/code]
[code]
JSP CODE:
$(document).ready(function() {
var oTable = $('#tableId').dataTable( {
"bprocessing": true,
"bServerSide": true,
"sAjaxSource": "/umResourceRequestController?do_action=listUsers",
"aoColumns": [
{ "mData": "appInstance" },
{ "mData": "usrId" },
{ "mData": "loginId" },
]
});
});
Servlet Code:
//List User
if ( do_action.equals("listUsers")){
ArrayList userlist = new RPUserDAO().getrpUserList(connection);
Gson gson = new Gson();
JsonElement element = gson.toJsonTree(userlist, new TypeToken() {}.getType());
JsonArray jsonArray = element.getAsJsonArray();
response.setContentType("application/json");
response.getWriter().print(jsonArray);
[/code]
This discussion has been closed.
Replies
Allan
Yes I did that too.. here the code which passes the parameter, but still it not working.
[code]
First Name
Last Name
Address 1
Address 2
$(document).ready(function() {
$('#tableId').dataTable( {
"bprocessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sAjaxSource": "umResourceRequestController",
"sServerMethod": "GET",
"aoColumns": [
{ "mData": "appInstance" },
{ "mData": "usrId" },
{ "mData": "loginId" }
],
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "do_action", "value": listUsers } );
}
});
});
[/code]