Vue中用axios发送请求,后台servlet接收参数为空

方法1:
1、修改axois的请求头header中的Content-type

'Content-type': 'application/x-www-form-urlencoded'
2、引入axois的qs,转换需要传的参数
import Qs from 'qs'
req.post('/ACPSample_AppServer/form05_6_2_AppConsume', Qs.stringify({
merId: merId,
txnAmt: merId,
orderId: orderId,
txnTime: txnTime
【Vue中用axios发送请求,后台servlet接收参数为空】})).then((result) => {
console.log(result)
})
参考:https://www.jianshu.com/p/13c4283975e8
方法二:
1、将参数作以下的处理
let params = new URLSearchParams();
params.append('merId', merId);
params.append('txnAmt', 'value2');
params.append('orderId', orderId);
params.append('txnTime', txnTime);
2、接下来就可以不改变请求头的情况下访问
req.post('/ACPSample_AppServer/form05_6_2_AppConsume', params).then((result) => {
console.log(result)
})
参考:https://segmentfault.com/q/1010000008476622
后台代码片段:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String merId = req.getParameter("merId");
String txnAmt = req.getParameter("txnAmt");
String orderId = req.getParameter("orderId");
String txnTime = req.getParameter("txnTime");
......
}

    推荐阅读