[英]How to pass json to post request with jsp?
I have problem with sending params to post method. 我在发送参数到发布方法时遇到问题。 Maybe, I'm sending the input parameters wrong there, beacause this request get 400 error
也许,我在这里将输入参数发送错误,因为此请求得到400错误
My strcuter of method: 我的方法的推手:
@RequestMapping(value = "/create", method = RequestMethod.POST, headers = "Accept=application/json")
public @ResponseBody
String createProject(@RequestBody TestClass project) {
return "success";
}
Object: 宾语:
public class TestClass {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
JSP: JSP:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Result</title>
</head>
<body>
Successful create project
</body>
</html>
And this i send from postman, but 400 error: image of postman 这是我从邮递员发送的,但出现400错误: 邮递员的图像
As per the spring documentation here , 根据此处的春季文档,
Expressions passed to the constructor with header names 'Accept' or 'Content-Type' are ignored.
传递给带有标题名称“ Accept”或“ Content-Type”的构造函数的表达式将被忽略。
Can you try with produces
and consumes
attributes for Accept and Content-Type? 你可以尝试
produces
和consumes
属性的接受和Content-Type?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.