iammonster 发表于 2013-1-23 02:25:20

action返回JSON数据结构的做法

action返回 JSON数据结构,做个笔记。
您是不是感觉有些没注意到的地方呢?
 
    /**   * 创建AJAX应答数据(JSON数据格式)   *      * @param response   *            输出   * @param obj   *            要封装的对象   * @return null   * @throws IOException   */    private static ActionForward buildJSONDate(final HttpServletResponse response, final Object obj) throws IOException    {       //设置编码      response.setContentType("application/json;charset=UTF-8");      response.setCharacterEncoding("UTF-8");      // 设置浏览器不要缓存      response.setHeader("Pragma", "No-cache");      response.setHeader("Cache-Control", "no-cache");      response.setDateHeader("Expires", 0);      final PrintWriter out = response.getWriter();      JsonUtil.toJson(out, obj); //把JSON数据结构写到输出流中      out.flush();      return null;    }
页: [1]
查看完整版本: action返回JSON数据结构的做法