How to pass the value from the javascript to servlet?

How do I pass a PlainObject to a Java servlet with JQuery.get?

  • My script looks something like: var x = {value: { json: $('#field1').val()}}; $.get('/myservlet', x, function(responseJson) { ....}}); And on the server side: doGet(HttpServletRequest req, HttpServletResponse response){ String zz = req.getParameter("value"); ... When I set x to something straightforward (e.g x = {value, "my value"}), it works. But as above, I get z==null. I expected, I dunno, maybe the JSON text or something. I thought jQuery said that I could pass a PlainObject. Does this not  count?  Or is there something I should be using other than getParameter?

  • Answer:

    I don't think there should be a problem. Check if the JSON object you are passing is correct. and also see if the object was sent to server or no.

Gourav Agarwal at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.