| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 输出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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 下载文件 |
| | | */ |
| | | public static void download(String file, String fileName, HttpServletResponse res) throws Exception { |
| | | download(file, fileName, res); |
| | | download(file, fileName, false, res); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 执行命令 |
| | | * |
| | | * @param cmd 命令 |
| | | */ |
| | | public static String exec2(String cmd) { |
| | | try { |
| | | StringBuilder sb = new StringBuilder(); |
| | | Process process = Runtime.getRuntime().exec(cmd); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | sb.append(line).append("\n"); |
| | | } |
| | | reader.close(); |
| | | |
| | | return sb.toString(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取请求的参数值 |
| | | * |
| | | * @param req 请求 |