Regarding Passing parameter to servlet in Datatable

Regarding Passing parameter to servlet in Datatable

rmanirmani Posts: 4Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
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]

Replies

  • ashiersashiers Posts: 101Questions: 8Answers: 7
    You might want to consider using the JED library. There are many examples on the JED website that demonstrate how to use DataTables on the Java platform. Check out: http://jed-datatables.ca/jed/
  • rmanirmani Posts: 4Questions: 0Answers: 0
    Thanks! But unfortunately I won't be able to use JED because of license agreement! Any help appreciated on this!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    The fnServerParams option is designed to be able to add parameters to what is sent to the server in the request.

    Allan
  • ashiersashiers Posts: 101Questions: 8Answers: 7
    Would you care to elaborate on the difficulty regarding the license agreement? Perhaps it is something I can look into?
  • rmanirmani Posts: 4Questions: 0Answers: 0
    Ashiers, company policy doesn't allow me to do it.
  • rmanirmani Posts: 4Questions: 0Answers: 0
    Hi 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]
This discussion has been closed.