private static void writer(HttpServletResponse response,String str){ try { StringBuffer result = new StringBuffer(); //设置页面不缓存 response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setCharacterEncoding("UTF-8"); PrintWriter out= null; out = response.getWriter(); out.print(str); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
public static void writerJson(HttpServletResponse response,Object object){ try { response.setContentType("application/json"); writer(response,JSONUtil.toJSONString(object)); } catch (JSONException e) { e.printStackTrace(); } }controller返回给jsp
//设置页面数据 Map<String,Object> jsonMap = new HashMap<String,Object>(); jsonMap.put("total",page.getPager().getRowCount()); HtmlUtil.writerJson(response, jsonMap);