- 创建方法
public static String renderJson(HttpServletResponse response, String content){
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
java.io.PrintWriter pw = null;
try{
pw = response.getWriter();
pw.write(content);
}catch (Exception e){
}finally{
pw.close();
}
return null;
}
- 在JSP中引入
public static String renderJson(HttpServletResponse response, String content){
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
java.io.PrintWriter pw = null;
try{
pw = response.getWriter();
pw.write(content);
}catch (Exception e){
}finally{
pw.close();
}
return null;
}