vue发送post请求到后台 方法一 axios:

前端

 var params = new URLSearchParams();
 params.append("hzguid",hzguid); 
 params.append("times",times); 
 this.$axios({
     method: 'post',
     url: 'http://localhost:8080/TestS/queryStemp',
     contentType: 'application/x-www-form-urlencoded',
     data:params,  
 }).then(function(response) {
     console.log("data:"+response.data);
     console.log("status:"+response.status);
     console.log("statusText:"+response.statusText);
     console.log("headers:"+response.headers);
     console.log("config:"+response.config);
     console.log("list:"+response.list);
     console.log("response:"+response)
     var list = response.data
     console.log("传递的参数:"+list)
     that.tableData = list
     console.log("table_data:"+that.tableData)
      }.bind(this)).catch(function (error) { 
           console.log(error);
      })

在使用axios时需要先引入插件

main.js
    import Axios from 'axios' 
    Vue.prototype.$axios = Axios

后台用servlet正常接收即可

web.xml:
    
  	SendQueryStemp
  	com.action.fabu.QueryStemp
  
  
  	SendQueryStemp
  	/queryStemp
   

action层:

public class QueryStemp extends HttpServlet{
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		/*
		5、查询运动历史 (ky.stl.sh.getstep)-----------------------------------------------------

			
				"Hzguid": "ddddddddddd",
				"begin": "2018-11-23T16:45:48.8623046+08:00",  //开始时间,可以不选择
				"end": "2018-11-26T16:45:48.8662109+08:00"     //结束时间
*/	
		String Hzguid = req.getParameter("hzguid");
		String times = req.getParameter("times");
		System.out.println(Hzguid);
		System.out.println(times);
    }
}

还有一种自己封装的方法 这里暂时先不做赘述  我会在后续进行更新

你可能感兴趣的:(学习笔记)