JSon字符串转JSon对象,使JSP页面直接返回JSON对象

来源:互联网 发布:淘宝买家信用等级查询 编辑:程序博客网 时间:2024/06/16 08:26
//JSon字符串转JSon对象;使JSP页面直接返回JSON对象 

//使用示例>>  在JSP代码里的最后一行加入 <% renderJson(response, json.toString()); %> 这段代码

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;}

原创粉丝点击