美文网首页
前端后台数据传递ajax

前端后台数据传递ajax

作者: 小铭铭_7c47 | 来源:发表于2018-11-30 23:53 被阅读0次

    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);
        }
    

    相关文章

      网友评论

          本文标题:前端后台数据传递ajax

          本文链接:https://www.haomeiwen.com/subject/puakcqtx.html