@RequestMapping(value = "getFilesName",
produces = "text/html;charset=utf-8")
@ResponseBody
public String getFilesName(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//String path = request.getServletContext().getRealPath("/") + "files/files.json";
String path = request.getServletContext().getRealPath("/files/files.json");
//response.setContentType("application/json");
String json = JSONFileUtils.readFile(path);
System.out.println(json);
//response.getWriter().print(json);
return json;
}
我发现这里的ResponseBody并没有帮我把数据写进response的body区,当我使用response.getWriter().print(json);页面才正常显示,这是为什么呢?