【问题标题】:How to pass json to post request with jsp?如何将json传递给jsp发布请求?
【发布时间】:2017-12-05 11:56:48
【问题描述】:

我在将参数发送到 post 方法时遇到问题。也许,我在那里发送错误的输入参数,因为这个请求得到 400 错误

我的方法设计者:

@RequestMapping(value = "/create", method = RequestMethod.POST, headers = "Accept=application/json")
  public @ResponseBody
  String createProject(@RequestBody TestClass project) {
  return "success";
  }

对象:

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:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Result</title>
</head>
<body>
Successful create project
</body>
</html>

这是我从邮递员发送的,但出现 400 错误: image of postman

【问题讨论】:

    标签: java json spring jsp post


    【解决方案1】:

    根据弹簧文档here

    传递给构造函数的表达式具有标头名称“Accept”或 'Content-Type' 被忽略。

    您可以尝试将 producesconsumes 属性用于 Accept 和 Content-Type 吗?

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 2018-02-02
      • 2021-03-25
      • 1970-01-01
      相关资源
      最近更新 更多