title: How to retrieve the array in server side using NanoHTTPD in Android when I post a array var in client side?
body: <p>In My.htm, I post a array var mytemp to server side, I hope to retrieve the array var in server side.</p>
  
  <p>I only get the a string <em>D 1,D,2,Tom'Dog</em> if I use the following code, how can I  retrieve the array in server side ? Thanks!</p>
  
  <p><strong>BTW, I hope to do a full post, not ajax, so I think that $.ajax() doesn't fit.</strong></p>
  
  <p><strong>My.htm</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  
      &lt;script src="js/jquery1.10.2.min.js?isassets=1" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
  
       $(function () {
          document.querySelector('#myformID').addEventListener('submit', event =&gt; {
             if (!confirm('Do you want to delete selected images?')) {
                event.preventDefault();
             }
          });
  
          $("#myformID").submit( function(eventObj) {
  
           var mytemp=new Array();
            mytemp.push("D 1");
            mytemp.push("D,2");
            mytemp.push("Tome'Dog");
  
  
             $('&lt;input /&gt;').attr('type', 'hidden')
                .attr('name', "myCw")
                .attr('value',mytemp)
               .appendTo('#myformID');
             return true;
          });
  
       });
  
      &lt;/script&gt;
  
  
  &lt;/head&gt;
  
  &lt;body&gt;
     &lt;div id="container"&gt;
         &lt;form action='' method='post' enctype='multipart/form-data' id="myformID"&gt;           
             &lt;input type='file' name='myfilename' /&gt; Please select a file
             &lt;input type='submit'name='submit' value='Delete Selecetd Items' /&gt;
         &lt;/form&gt;
  
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code>public class HttpServer extends NanoHTTPD {
  
     private Context mContext;
  
     public HttpServer(Context myContext) throws IOException {
          super(PublicParFun.GetWebPort(myContext));
          this.mContext=myContext;
          start(NanoHTTPD.SOCKET_READ_TIMEOUT);
     }
  
  
      private Response POST(IHTTPSession session) {
           Utility.LogError("Handle Post");
  
          try {
              Map&lt;String, String&gt; files = new HashMap&lt;String, String&gt;();
              session.parseBody(files);
  
  
              Set&lt;String&gt; keys1 =session.getParms().keySet() ;
              for(String key: keys1){
                  String name = key;
                  String loaction =session.getParms().get(key);                
              }          
  
          } catch (Exception e) {
              Utility.LogError("This is an error "+e.getMessage() );
              System.out.println("i am error file upload post ");
              e.printStackTrace();
          }
          return newFixedLengthResponse(Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT,"I'm Hello!");
      }
  
  
  
  
      @Override
      public Response serve(IHTTPSession session) {
  
          String uri = session.getUri();
          Method method = session.getMethod();
  
          MURLPar mURLPar=new  MURLPar(mContext);
          FileFolderHelper.SetMURLParValue(mURLPar,session);
  
          if (mURLPar.isassets.value!=null &amp;&amp; mURLPar.isassets.value.equals("1")){
              return GetResponseInputByAssetsFile(uri);
          }
  
  
          if (Method.POST.equals(method)) {      
              return POST(session);
          }
  
  
          String s=FileFolderHelper.GetStringTemplate(mContext,mContext.getString(R.string.WebImageBase));
          return newFixedLengthResponse(s);
      }
  }
  </code></pre>
  
  <p>To Erfan Mowlaei: Thank you! Is the following code OK?</p>
  
  <p><strong>Client Side:</strong></p>
  
  <pre><code>  var mytemp=new Array();
         mytemp.push("D 1");
         mytemp.push("D, 2");
         mytemp.push("D'3");
  
  
         $("#myformID").submit( function(eventObj) {
             $('&lt;input /&gt;').attr('type', 'hidden')
                .attr('name', "myCw")
                .attr('value', JSON.stringify(mytemp))
               .appendTo('#myformID');
             return true;
        });
  </code></pre>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code> public ArrayList&lt;String&gt; jsonStringToArray(String jsonString) throws JSONException {
  
          ArrayList&lt;String&gt; stringArray = new ArrayList&lt;String&gt;();
  
          JSONArray jsonArray = new JSONArray(jsonString);
  
          for (int i = 0; i &lt; jsonArray.length(); i++) {
              stringArray.add(jsonArray.getString(i));
          }
  
          return stringArray;
      }
  </code></pre>