繁体   English   中英

将 JSON 数据从 JQUERY 传递到 java Z594C103F2C6E304C3D8AB0E5C 时出现异常

[英]Getting exception while passing JSON data from JQUERY to java controller

I am passing JSON data from jQuery to my Java controller and I am using @RequestBody , but I am getting an exception saying:

org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型'application/x-www-form-urlencoded;charset=UTF-8'

我传递的数据是:

myData = {
  "source": "CSS",
  "type": "CSS2",
  "typeValue": "value",
  "textarea_value": " desc"
}:

我用来传递此数据的 AJAX 调用是:

$.ajax({
  url: './common/deleteData',
  type: 'POST',
  data: myData,
  success: function(data) {
    alert("Successfully Deleted Source..");
  },
  error: function(data) {}
});  

我的 Java Controller 如下

@RequestMapping(value = "/common/deleteData", method = RequestMethod.POST, consumes = {"application/x-www-form-urlencoded; charset=UTF-8"})
public String deleteData(@RequestBody SourceDelete sourcedelete, final HttpServletRequest request, final RedirectAttributes rdtAttribs) throws ApplicationException 
{
  LOGGER.entry("Deleting the Merge Preference Details");
  System.out.println(sourcedelete.getSource());
  return null;
}

我的 POJO object 如下:

public class SourceDelete {
  private String source;
  private String type;
  private String typeValue;
  private String textarea_value;
  //Setters and Getters
}

有人可以帮我弄清楚为什么我会收到这个错误以及我应该如何解决它。

删除 @RequestBody 注释,

@RequestMapping(value = "/common/deleteData", method = RequestMethod.POST, consumes = {"application/x-www-form-urlencoded; charset=UTF-8"})
public String deleteData(SourceDelete sourcedelete, final HttpServletRequest request, final RedirectAttributes rdtAttribs) throws ApplicationException 
{
  LOGGER.entry("Deleting the Merge Preference Details");
  System.out.println(sourcedelete.getSource());
  return null;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM