Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple of issues you need to resolve first, are you doing this in an AJAX style of request? is this a form submission? is there going to be on-going interaction within the page-session between the client/server passing JSON objects back-and-forth?</p> <p>Lets tackle the simple case of a form submission, once you get that you should be able to get the remaining cases going as they are just "extensions" of this base case. Say you have some form that will submit the data in some field:</p> <pre><code>&lt;form name='my_form' id='my_ford_id'&gt; &lt;input type='hidden' name='my_input_field' /&gt; &lt;/form&gt; </code></pre> <p>then at some point in time you have a piece of code that executes and you have your JSON object</p> <pre><code>function myFunction() { var json_data = getJsonData(); document.forms['my_form']['my_input_field'].value = json_data; document.forms['my_form'].submit(); } </code></pre> <p>You will then on the JSP side receive this data as a JSON string inside of a form field, at which point you need to process it, lets assume you have some kind of a JSON library available to you, the code might look something like this:</p> <pre><code>&lt;% String myInputField = request.getParameter("my_input_field"); if(myInputField != null) { try { JSONObject myObject = new JSONObject(myInputField); } catch(JSONException e) { } } %&gt; </code></pre> <p>If you need an "AJAX" style of interaction, you will be making a number of such requests in the page, but fundamentally it falls back to the original problem of submitting the data. Since you are using forms in this example, and JSP, you don't have to worry at any point about encoding, the browser/server will take care of things for you.</p>
 

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