开发者

JSON and Firefox in Spring MVC 3.0 and ExtJS

I'm using Spring MVC 3.0 to develop my web application. I'm using the new feature开发者_如何学运维 ContentNegotiation to return back JSON data for client. At client I use ExtJS to design the UI and display the content of web. In IE and Chrome ExtJS displays normal with response JSON data, but in Firefox and Opera it downloads that json as a file. What I should do to fix this error?


You should set the Content Type appropriately:

@RequestMapping(value="/json", method=GET)
public ResponseEntity<String> jsonAction() {
  String json = ...;
  HttpHeaders responseHeaders = new HttpHeaders();
  responseHeaders.setContentType(MediaType.APPLICATION_JSON);
  return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜