Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve the data sent as JSON from JavaScript, inside a servlet
    primarykey
    data
    text
    <p>I have a query on retrieving data sent as JSON from a JavaScript, inside a Java servlet. Following is what I am doing...</p> <p>This is the part of the code inside JavaScript making a request to a servlet</p> <pre><code>type : "POST", url: 'getInitialData', datatype: 'json', data : ({items :[{ name: "John", time: "2pm" },{name: "Sam", time: "1pm" }]}), success: function(data) { try{ ////Code to be handeled where response is recieved }catch(e){ alert(e); } } </code></pre> <p>On making this request I try to retrieve the parameters sent from JavaScript in a Servlet, but while doing so I was firstly confused on how to retrieve the dat from the request </p> <p>I used the following in my servlet: </p> <p><strong>NOTE :</strong> the content Type in my Servlet is set to : <strong>apllication/json</strong></p> <pre><code> response.setContentType("application/json"); request.getParameterMap(); </code></pre> <p>the above showed me the data as below, but I was not able figure out how to work and get the actual data</p> <pre><code>{items[1][name]=[Ljava.lang.String;@1930089, items[0][time]=[Ljava.lang.String;@860ba, items[1][time]=[Ljava.lang.String;@664ca, items[0][name]=[Ljava.lang.String;@1c334de} </code></pre> <p>while the following code gave me Exception of null which was expected.</p> <pre><code>request.getParametervalues("items"); </code></pre> <p>Among the others i tried where request.getParameter(); request.getParameterNames(); but in vain...</p> <p>Am I in a wrong direction? Please guide me! Please let me know how to retieve these value.</p> <p>Thank You for reading this long post...</p> <p>Sangeet</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload