When I try to send data to server by POST method, I got this error on the server side:
java.lang.IllegalArgumentException: "json" does not contain '/'.
First I thought that date format from jQuery UI DatePicker is wrong and I changed it to "yy-mm-dd", but unfortunately is still does not work. I am really confused, because I don't know where is '/' which makes me trouble. I would be very happy if anybody decides to help me - Thank you
This is error, $.ajax and mapping are also below:
java.lang.IllegalArgumentException: "json" does not contain '/'
at org.springframework.http.MediaType.parseMediaType(MediaType.java:648)
at org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition$ConsumeMediaTypeExpression.matchMediaType(ConsumesRequestCondition.java:215)
at org.springframework.web.servlet.mvc.condition.AbstractMediaTypeExpression.match(AbstractMediaTypeExpression.java:63)
at org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition.getMatchingCondition(ConsumesRequestCondition.java:165)
at org.springframework.web.servlet.mvc.method.RequestMappingInfo.getMatchingCondition(RequestMappingInfo.java:174)
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:64)
// snip
That is how I send data:
$.ajax({
url: _getContextPath() + "/event/addEvent",
method: "POST",
contentType: "json",
data: {
"ownerId": $("#ownerIdHidden").val(),
"title": $("#title").val(),
"place": $("#place").val(),
"startdate": $("#startDate").val(),
"starthour": $("#startHour").val(),
"duration": $("#duration").val(),
"description": $("#eventDescription").val(),
"invited": _getLoginsFromTable(invitedTable)
}
});
And here is how I try to map it in Spring MVC Cotroller:
@ResponseBody
@RequestMapping(value="event/addEvent", method=RequestMethod.POST,
consumes="application/json")
public String addEvent(@RequestParam("ownerid") Long ownerid, @RequestParam("title") String title,
@RequestParam("place") String place, @RequestParam("startdate") Date startDate,
@RequestParam("starthour") Integer startHour, @RequestParam("duration") Integer duration,
@RequestParam("description") String description, @RequestParam("invited") String[] invitedLogins){
Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
try{
(....)
UPDATE: now this is the code:
$.ajax({
url: _getContextPath() + "/event/addEvent",
method: "POST",
contentType: "application/json",
data: {
"ownerId": 3,
"title": 3,
"place": $("#place").val(),
"startdate": (new Date($("#startDate").val())).getTime(),
"starthour": $("#startHour").val(),
"duration": $("#duration").val(),
"description": $("#eventDescription").val()
}
});
And mapping:
@ResponseBody
@RequestMapping(value="event/addEvent", method=RequestMethod.POST,
consumes="application/json")
public String addEvent(@RequestParam("ownerid") Long ownerid, @RequestParam("title") String title,
@RequestParam("place") String place, @RequestParam("startdate") Long startDateMilis,
@RequestParam("starthour") Integer startHour, @RequestParam("duration") Integer duration,
@RequestParam("description") String description){
Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
try{
And now I got: POST http://localhost:8084/pracainz/event/addEvent 400 (Bad Request)