title: how to create a json object in jsp?
body: <p>I created a JSP page with few input fields. When i click on submin, i need the javascript to create json object and put input values in it and i want to display the json data in same jsp page.</p>
  
  <p>This is my form</p>
  
  <pre><code>&lt;form name="jsond" method="get"&gt;
  &lt;br&gt;
  &lt;p id="msg"&gt;&lt;/p&gt;
  First Name:
  &lt;input type="text" id="firstName"/&gt;&lt;br&gt;
  Last Name:
  &lt;input type="text" id="lastName"/&gt;&lt;br&gt;
  E-mail:
  &lt;input type="text" id="email"/&gt;&lt;br&gt;
  Mobile No:
  &lt;input type="text" id="mobile"/&gt;&lt;br&gt;
  Place:
  &lt;input type="text" id="place"/&gt;&lt;br&gt;
  Country:
  &lt;input type="text" id="country"/&gt;&lt;br&gt;
  &lt;br&gt;
  &lt;input type="submit" name="submit" value="Submit" onclick="return submitForm(this, event);"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And this is my script</p>
  
  <pre><code>function submitForm(thisObj, thisEvent) {
         var firstName = document.forms["jssond"]["firstName"].value;
         var lastName = document.forms["jssond"]["lastName"].value;
         var email = document.forms["jssond"]["email"].value;
         var mobile = document.forms["jssond"]["mobile"].value;
         var place = document.forms["jssond"]["place"].value;
         var country = document.forms["jssond"]["country"].value;
  
  // How to do the remaining code? I want to store the above variables in json object and display json values in &lt;p id="msg"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>How to pass the json object to servlet from javascript?</p>
  
  <p>Thanks</p>