pan_java 发表于 2013-1-23 02:41:26

JSON ajax 页面输出工具

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");}}
页: [1]
查看完整版本: JSON ajax 页面输出工具