title: How to pass multiple parameters with JSON on Servlet to Ajax
body: <p>I have JavaScript code that should get two parameters from servlet:<br>
  player name and player type (Human \ Computer)  </p>
  
  <p>The JavaScript use Ajax to send the request to the servlet named: UpdateStatusPaneServlet.java  </p>
  
  <p>On the servlet I created <code>ArrayList&lt;String&gt;</code> of 2 parameters and sent it to the Ajax.  </p>
  
  <p>You can see in the picture that the array appears ok.  </p>
  
  <p>I am not sure how to get the parameters using the <code>indexOf()</code> function or maybe I need to use other function.<br>
  I also tried with <code>get()</code> but it didn't work.<br>
  Also with playerNameAndType[0] it just print <code>'['</code></p>
  
  <p><img src="https://i.stack.imgur.com/KHIrb.png" alt="enter image description here"></p>
  
  <p><strong>JavaScript</strong>:</p>
  
  <pre><code>function printStatusPane() {
  
      $.ajax({
          url: "UpdateStatusPaneServlet",
          timeout: 2000,
          error: function() {
              console.log("Failed to send ajax");
          },
          success: function(playerNameAndType) {
              console.log("GOT ajax: " + playerNameAndType);
              $("#currentPlayer").append(playerNameAndType.indexOf(0));
              $("#playerType").append(playerNameAndType.indexOf(1));
          }
      });
  }
  </code></pre>
  
  <p><strong>Servlet (Java)</strong>:</p>
  
  <pre><code>  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
           response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
          try {
              Gson gson = new Gson();
              String currentPlayerNameJSON = "";
              String playerTypeJSON = "";
              Engine engine = (Engine)getServletContext().getAttribute("engine");
              ArrayList&lt;String&gt; JSONRequest = new ArrayList&lt;String&gt;(2);
  
              currentPlayerNameJSON = gson.toJson(engine.GetCurrentPlayer().GetPlayerName());
              playerTypeJSON = gson.toJson(engine.GetCurrentPlayer().GetPlayerType().toString());
  
              JSONRequest.add(currentPlayerNameJSON);
              JSONRequest.add(playerTypeJSON);
              out.print(JSONRequest);
  
          } finally {
              out.close();
          }
      }
  </code></pre>