action 返回 json 数据

    技术2025-07-10  14

    /** * 创建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; }

    最新回复(0)