JQuery $.ajax() post - data in a java servlet

后端 未结 4 1263
面向向阳花
面向向阳花 2020-12-02 17:11

I want to send data to a java servlet for processing. The data will have a variable length and be in key/value pairs:

{ A1984 : 1, A9873 : 5, A1674 : 2, A87         


        
4条回答
  •  一整个雨季
    2020-12-02 17:27

    For the time being I am going a different route than I previous stated. I changed the way I am formatting the data to:

      &A2168=1&A1837=5&A8472=1&A1987=2
    

    On the server side I am using getParameterNames() to place all the keys into an Enumerator and then iterating over the Enumerator and placing the keys and values into a HashMap. It looks something like this:

    Enumeration keys = request.getParameterNames(); 
    HashMap map = new HashMap(); 
    String key = null; 
    while(keys.hasMoreElements()){ 
          key = keys.nextElement().toString(); 
          map.put(key, request.getParameter(key)); 
    }
    

提交回复
热议问题