| | |
| | | } |
| | | |
| | | /** |
| | | * 输出json数据到前端 |
| | | * 输出str至前端 |
| | | */ |
| | | public static boolean write2Page(HttpServletResponse response, String jsonPack) throws IOException { |
| | | response.setContentType("application/json;charset=UTF-8"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setHeader("Pragma", "No-cache"); |
| | | response.setDateHeader("Expires", 0); |
| | | public static boolean writeStr2Page(HttpServletResponse res, String str) { |
| | | try { |
| | | res.setContentType("application/json;charset=UTF-8"); |
| | | res.setHeader("Cache-Control", "no-cache"); |
| | | res.setHeader("Pragma", "No-cache"); |
| | | res.setDateHeader("Expires", 0); |
| | | |
| | | PrintWriter out = response.getWriter(); |
| | | out.print(jsonPack); |
| | | PrintWriter out = res.getWriter(); |
| | | out.print(str); |
| | | |
| | | out.flush(); |
| | | out.close(); |
| | | out.flush(); |
| | | out.close(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 输出json至前端 |
| | | */ |
| | | public static void writeJson2Page(HttpServletResponse res, String str) { |
| | | String json = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, str)); |
| | | writeStr2Page(res, json); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 写响应信息 |
| | | */ |
| | | public static void writeInfo(HttpStatus status, String info, HttpServletResponse res) { |
| | | try { |
| | | WebHelper.write2Page(res, WebHelper.getErrJson(status, info)); |
| | | } catch (Exception e) { |
| | | // |
| | | } |
| | | WebHelper.writeStr2Page(res, WebHelper.getErrJson(status, info)); |
| | | } |
| | | |
| | | /** |