title: how to send multiple variables from servlet as response to ajax post?
body: <p>I am developing a testing system with jsp and java </p>
  
  <p>At client side i have the following code: </p>
  
  <pre><code>        var xmlhttp = new getXmlHttpRequestObject(); //xmlhttp holds the ajax object
  
  
          function servletPost() {
              if(xmlhttp) { 
                  //var txtname = document.getElementById("testForm");
                  var form = $('#testForm');
                  xmlhttp.open("POST","servlet/TestingController",true);
                  xmlhttp.onreadystatechange = handleServletPost;
                  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                  xmlhttp.send(form.serialize()); 
              }
          }
  
          function handleServletPost() {
              //var qComplexity = document.getElementsByName("qComplexity")[0].value;  
  
  
              if (xmlhttp.readyState == 4) {
                  if(xmlhttp.status == 200) {
                      var respText = xmlhttp.responseText;
  
                      document.getElementById("fullQuestion").innerHTML = respText;
                      // here i also should change the content of the answer options
                      // so i should get from servlet multiple variables
                      // which allows me to change div contents in my jsp like as respText.question or respText.answer[0]
                  } else {
                      alert("Ajax calling error");
                  }                    
             }
          }
  </code></pre>
  
  <p>At server side: (my Servlet)</p>
  
  <pre><code>public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
   .........................................................
   .........................................................
  
   PrintWriter out = res.getWriter();
   String complex = null;
          int categ_id = -1;
          String asked_by = null;
          String Qtext = null;
          int qid = -1;
          q_numb = 1;
          q_numb++;
          String sqlSelect = "SELECT * FROM questions WHERE complexity = '" + complexity 
                          + "'ORDER BY RANDOM() LIMIT 1;";
  
          ResultSet r = myConnection.runQuery( sqlSelect );
          session.setAttribute("member", tempMem);
  
          while (r.next()) {
              complex = r.getString(5);
              categ_id = r.getInt(4);
              asked_by = r.getString(3);
              Qtext = r.getString(2);
              qid = r.getInt(1);
  
              String sqlA = "select * from answers where question_id = '" + qid 
                                  + "' ORDER by RANDOM();";
  
              ResultSet result = myConnection.runQuery( sqlA );
              session.setAttribute("member", tempMem); }
  </code></pre>
  
  <p>So i need to send values of complex, Qtext, qid, categ_id and so on.
  Is there any structures to send like from ajax to servlet, but visa versa? 
  And how to handle sent data in client side? </p>
  
  <p>Thanks in advance!!!!</p>