六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

JSON ajax 页面输出工具

[复制链接]

升级  46%

31

主题

31

主题

31

主题

秀才

Rank: 2

积分
119
 楼主| 发表于 2013-1-23 02:41:26 | 显示全部楼层 |阅读模式
import java.io.IOException;import java.io.PrintWriter;import javax.servlet.http.HttpServletResponse;import org.json.JSONArray;import org.json.JSONObject;/** * Ajax 页面输出工具 * @author panxiuyan * */public final class AjaxResponsePrintUtil {    /**     * 输出 JSONObject     * @param response     * @param obj     */public static void writer(final HttpServletResponse response,final JSONObject obj) {initReponse(response);PrintWriter pw = null;try {pw = response.getWriter();pw.write(obj.toString());} catch (IOException e) {// TODO Auto-generated catch blockthrow new RuntimeException(e);}}/** * 输出 JSONArray * @param response * @param obj */public static void writer(final HttpServletResponse response, final JSONArray obj) {initReponse(response);PrintWriter pw = null;try {pw = response.getWriter();pw.write(obj.toString());} catch (IOException e) {// TODO Auto-generated catch blockthrow new RuntimeException(e);}}private static void initReponse(HttpServletResponse response) {response.setContentType("text/xml; charset=UTF-8");response.setHeader("Cache-Control", "no-cache");}}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表