[英]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.