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

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐