当访问给定的 URL 时,我试图将 json 列表从控制器发送到 javascript。使用此代码,当我转到 URL 时收到 406 错误。我的 servlet 上下文有<annotation-driven />
并且我有org.codehaus.jackson
Maven 依赖项。有没有其他原因给我一个 406,或者有没有更好的方法来发送一个列表到 javascript?
控制器功能
@RequestMapping(value = "/{room}/handhygiene.json", method = RequestMethod.GET)
public @ResponseBody ArrayList<Integer> getHandHygienePageAsync(
@PathVariable(value = "room") String roomCode) {
ArrayList<Integer> json = new ArrayList<Integer>();
Room room = getRoom(roomCode);
json.add(service.getHandHygieneEvents(room));
if (room.isGroupBased()) {
json.add(service.getRoomEntryExits(room));
}
if (room.isIdBased()) {
json.add(service.getPatientContacts(room));
}
return json;
}
Javascript
$.getJSON(currentURL + ".json",
function(data){
alert('I can\'t get here though');
var overallRatio;
var handWash = data[0];
$("#handwash").html(handWash);
if(groupBased == true)
{
var enex = data[1];
$("#enex").html(enex);
overallRatio = "" + Math.round((handWash*100)/enex) + "%";
}
else
{
if(idBased == true)
{
var contacts = data[2];
$("#contacts").html(contacts);
overallRatio = "" + Math.round((handWash*100)/contacts) + "%";
}
}
$("#overall").html(overallRatio);
}
);
这是请求的标头
GET /groupbased/ICU6/handhygiene.json HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Referer: http://localhost:8080/groupbased/ICU6/handhygiene
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: JSESSIONID=063CDE4BF5FB7369B6C48FC2EADFD8E9
这个视图解析器会与任何东西冲突吗?
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}