Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my AJAX code which triggers the Servlet 'CalculateLace':

laceTd.dblclick(function() {

    var jsonObj= { jsonObj: [ {"rowID": $(nRow).attr('id')}  ]};                                    

    $.ajax({

        data: JSON.stringify(jsonObj),

        contentType: "application/json; charset=utf-8",

        traditional: true,

        url: "CalculateLace"

    });

});

This is the Java Servlet code:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

            throws ServletException, IOException {

      String id = req.getParameter("rowId");

      //do something

}

But I get String id as null every time I run it. Can anyone tell me what I’m doing wrong here? 

1 Answer

0 votes
by (19.7k points)

You can try it like below: 

var jsonObj= {"rowId": $(nRow).attr('id')};

To get rowID in the servlet, parse the JSON from JSON.org: 

JSON.org

req.getParameter("rowId");

Interested in Java? Check out this Java Certification by Intellipaat.   

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...