- http = new HttpClient**();//此处封装一下发请求的类
- Map<String, String> map = new HashMap<String, String>();
- map.put("sql", sql);
- JSONObject json = JSONObject.fromObject(vMap);
- map.put("vMap", json.toString());
- http.post(url+ "/common***/action/save.action", map);
- String str = "";
- if (http.getResponse().getStatus() == 200) {
- try {
- str = http.getResponse().getBody();
- }catch (Exception e1) {
- e1.printStackTrace();
- throw new Exception("未取到元数据");
- }
- }
- return str;
服务器端Action接收:
[java] view plain copy
- String sql = request.getParameter("sql");
- String str = request.getParameter("valueMap");
方法:
[java] view plain copy
- public static Map parserToMap(String s){
- Map map=new HashMap();
- JSONObject json=JSONObject.fromObject(s);
- Iterator keys=json.keys();
- while(keys.hasNext()){
- String key=(String) keys.next();
- String value=json.get(key).toString();
- if(value.startsWith("{")&&value.endsWith("}")){
- map.put(key, parserToMap(value));
- }else{
- map.put(key, value);
- }
- }
- return map;
- }
时间: 2024-10-13 10:53:57