Back Forum Reply New

from status 406

Hi,

I'm using SpringMVC for my web application. In one of the JSPs I'm making an Ajax call using jQuery and retrieving a list of objects.

my jsp calls

Code:
lt;script type=quot;text/javascriptquot;gt;
function getCities() {
jq(function() {
jq.post(quot;getCities.htmlquot;,
{ stateSelect:  jq(quot;#stateSelectquot;).val()},
function(data){
jq(quot;#citiesquot;).replaceWith('lt;span id=quot;citiesquot;gt;Changedlt;/spangt;');
});
});
}
lt;/scriptgt;
The getCities is mapped to the following:

Code:
@RequestMapping(value = quot;/getCitiesquot;, method = RequestMethod.POST)   public @ResponseBody Listlt;StateNamesgt; getCities(@RequestParam(value=quot;stateSelectquot;, required=true) String stateName,   Model model) {
// Delegate to service to do the actual adding
Listlt;StateNamesgt; listStates = myService.listCityNames(stateName);

// @ResponseBody will automatically convert the returned value into JSON format
// You must have Jackson in your classpath
return listStates;
}
I get the following error when I run this.Code:
406 Not Acceptable   The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
Please guide me.
I used Firbug to see what's going on. Here's what i get:

Code:
Response Headers
ServerApache-Coyote/1.1
Content-Typetext/html;charset=utf-8
Content-Length1070
DateSat, 12 Feb 2011 13:09:44 GMT

Request Headers
Hostlocalhost:8080
User-AgentMozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept*/*
Accept-Languageen-us,en;q=0.5
Accept-Encodinggzip,deflate
Accept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive115
Connectionkeep-alive
Content-Typeapplication/x-www-form-uclencoded; charset=UTF-8
X-Requested-WithXMLfromRequest
RefererMyApplication/
Content-Length17
CookieJSESSIONID=640868A479C40792F8AB3DE118AF12E0
Pragmano-cache
Cache-Controlno-cache
Please guide me.

I suppose you're using the wrong JQuery function since the accept header

Code:
Accept: application/json, text/javascript, */*
is missing, use postJSON() instead.

Robin.


Originally Posted by robinI suppose you're using the wrong JQuery function since the accept header

Code:
Accept: application/json, text/javascript, */*
is missing, use postJSON() instead.

Robin.

I've also tried with postJSON, but I guess that's not the problem. I keep getting the same error.

I racked my brains for the whole day amp; came to realize that if i send String, Integer as replies from my controller back to the jsp, the whole thing works well.
But the time I start sending objects/List of Objects, the code breaks with from 406?
Why is it so?
Please help.

I also tried the getJSON function and got the same from 406 error:Code:
Response Headers
ServerApache-Coyote/1.1
Content-Typetext/html;charset=utf-8
Content-Length1070
DateSun, 13 Feb 2011 14:38:16 GMT

Request Headers
Hostlocalhost:8080
User-AgentMozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Acceptapplication/json, text/javascript, */*; q=0.01
Accept-Languageen-us,en;q=0.5
Accept-Encodinggzip,deflate
Accept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive115
Connectionkeep-alive
x-requested-withXMLfromRequest
RefererAuditions/
CookieJSESSIONID=62D82E42596B6C8E31EEC76AF28EA81EIn order to isolate the problem I would start with allowing a GET request for that method and return a single StateNames instance. Then test the returned value by calling the ucl using:

Code:
cucl -X GET -H quot;Content-Type: application/jsonquot; getCities
Do you see json content or not?
Then I would change the return value back to a list. I'm not sure whether this is supported out of the box, I'm am using a list of values but only wrapped in a return object, not in the return value itself. I can't remember if the reason was that it isn't supported or if this is just an coincendence.
¥
Back Forum Reply New