简体   繁体   English

向控制器发送表格数据时,出现415不支持的媒体类型错误

[英]Am getting 415 unsupported media type error while sending form data to controller

This is the jquery function which returns 415 media type not found error 这是返回415媒体类型未找到错误的jquery函数

$('#save').on('click',function(){
    alert("test");
    var data = JSON.stringify(jQuery('#form').serializeArray());
    console.log("data"+data);
    $.ajax({
        type: "POST",
        url: "saveExpenses",
        data: JSON.stringify(jQuery('#form').serializeArray()),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: true,
        success: function(data){alert("Success");}
    })
})

and the controller: 和控制器:

@RequestMapping(value="/saveExpenses",method=RequestMethod.POST)
public String saveExpense(@RequestBody ExpensesSummary expenses, HttpServletRequest request,HttpSession session){
    System.out.println("first name"+expenses.getFirstName());
    String message = homeBankingDao.expenseSummary(expenses);
    request.getSession().setAttribute("message",message);
    return "login";
}

Perhaps you should have a look to produce and consume annotations and attributes. 也许您应该看看如何生成和使用注释和属性。 Those posts may certainly help: 这些帖子当然可以帮助您:

Or I don't get it... 或者我不明白...

EDIT : 编辑

  • if the error (415) is thrown from your jquery function then you should certainly also define the "accept: application/json" thing in your original query. 如果从您的jquery函数抛出错误(415),那么您当然也应该在原始查询中定义“ accept:application / json”。 Cf. cf. this post . 这个帖子

  • If server-side, you should also check that Jackson is present in your libraries. 如果是服务器端,还应该检查库中是否存在Jackson。 Cf. cf. this post . 这个帖子

暂无
暂无

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

相关问题 从Jsp向Rest Controller发送Json数据时获取415(不支持的媒体类型错误) - Getting 415(Unsupported media type error) while sending the Json data from Jsp to Rest Controller 为什么会出现媒体类型不受支持的415错误? - Why am I getting Media type unsupported 415 error? 尝试使用Ajax请求从Spring控制器返回视图时,出现415不支持的媒体类型错误 - Getting 415 Unsupported Media Type Error when trying to return a view from a spring controller using an Ajax Request 获取“不支持的媒体类型”错误 415(八位字节流) - Getting "Unsupported Media Type" error 415 (octet-stream) POST到Jersey REST服务收到错误415不支持的媒体类型 - POST to Jersey REST service getting error 415 Unsupported Media Type 尝试进行JSON调用时出现415(不支持的媒体类型)错误 - 415 (Unsupported Media Type) error while trying to make a JSON call 眨眼上传时出现错误415(不支持的媒体类型) - Error 415 (Unsupported Media Type) while uploading with wink 当我尝试使用JSON数据时,POST到Jersey REST服务获取错误415不支持的媒体类型 - POST to Jersey REST service getting error 415 Unsupported Media Type when I try to consume JSON data 415不支持的媒体类型AngularJS到SpringMVC控制器 - 415 Unsupported Media Type AngularJS to SpringMVC Controller 与Spring MVC控制器绑定JSON数据时,出现“错误不受支持的媒体类型” - getting “error Unsupported Media Type” while binding JSON data with spring mvc controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM