前端后台数据传递ajax

2018-11-30  本文已影响0人  小铭铭_7c47

Personal项目map1.jsp片段:

window.pathSimplifierIns = pathSimplifierIns;
var id = "11"; 
var date = "2018-10-10";
var form = {};
form["userId"] = id;
form["date"] = date;
var formDate = {};
formDate["userId&date"] = JSON.stringify(form);
$.ajax({
       url : '<%=request.getContextPath()%>/GaodeMap/road',
       type : 'POST',
       data : formDate ,
       dataType : 'json',
       success : function(data) {               
        pathSimplifierIns.setData(data);
       }
})
console.log("11aa");

GaodeMap.java() 公司在用的 import com.google.gson.Gson

import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import hehaoming.service.RoadServiceInterf;
@Controller
@RequestMapping("/GaodeMap")
public class GaodeMap extends HttpServlet 
implements RoadServiceInterf{   
    public static Gson gson = new GsonBuilder().create();
    
    @SuppressWarnings({ "unused", "rawtypes" })
    @RequestMapping(value="/road", method = RequestMethod.POST)
    protected void dopost
    (HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException {
        
        String userId_date = request.getParameter("userId&date");
        Map map = new HashMap();
        map = gson.fromJson(userId_date, Map.class);
        String userId = (String) map.get("userId");
        String date = (String) map.get("date");
        try {
            RoadServiceInterf.searchRoad(userId,"2018-10-10");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
        String jsonStr = gson.toJson(map);  
        String s ="[{\"name\":\"18-11-01\",\"points\":[{\"name\":\"13:29:59\",\"lnglat\":[\"121.42003\",\"31.21001\"]},{\"name\":\"13:30:59\",\"lnglat\":[\"121.42010\",\"31.20990\"]}]}]";
        response.getWriter().write(s);
    }
上一篇下一篇

猜你喜欢

热点阅读