这里采用的是非注解形式,相当于注解中的@responseBody
/** * 根据字符串输出JSON,返回null * * @param jsonString * @return */ public String ajaxJson(HttpServletResponse response,String jsonString) { return ajax(response,jsonString, "text/html"); }
/** * 返回json字符串(非注解形式) * AJAX输出,返回null * * @param content * @param type * @return */ public String ajax(HttpServletResponse response, String content, String type) { try { response.setContentType(type + ";charset=UTF-8"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { e.printStackTrace(); logger.error("IOException:", e); } return null; }
时间: 2024-10-10 17:16:34