【发布时间】:2018-04-05 12:58:04
【问题描述】:
我有 React JS 应用程序,我使用 axios 库将 post 请求发送到服务器并提交表单。
客户请求:
sendData(data,price) {
axios.post('http://localhost:8080/SampleJavaAPP/UserServer', {
item: data,//these value
price:price//these value
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
我不确定如何将这些值输入到我正在服务器中获取这样的值的服务器中
String name = request.getParameter("item");
String price = request.getParameter("price");
System.out.println("Result "+name + price);
但它在服务器中给出空值。如何在服务器中接收这些值参数?
【问题讨论】:
-
您是否在发布请求之前尝试过 console.log(data, price) 以澄清问题的根源?
-
是的值正在控制台中打印,但它在服务器中给出 null...
-
您使用什么来编写服务器端软件?请注意,使用 React 发出请求并不重要。无论他们使用什么语言或框架,所有客户端都将以完全相同的方式发出 HTTP 请求。
-
我在服务器端使用 java j2EE spring mvc 框架...但是请求正在访问服务器,但参数值为空,如我所述。
-
stackoverflow.com/questions/3831680/… 您正在发送无法直接作为表单数据读取的 json 数据。
标签: java server httprequest axios