protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("content-type", "text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); StringBuilder Str = new StringBuilder(""); String logmark = tostr.to_utf_8(request.getParameter("logmark")); if (logmark.equals("list")) // 打印数据 { String filename = ""; String mgid = tostr.to_utf_8(request.getParameter("mgid")); String ShowPage = tostr.to_utf_8(request.getParameter("page")); // 页码,起始值 1 String PageSize = tostr.to_utf_8(request.getParameter("rows")); // 每页显示行 if (!checkStr.checkIsNum(ShowPage)) ShowPage = "1"; if (!checkStr.checkIsNum(PageSize)) PageSize = "30"; if (!checkStr.checkIsNum(mgid)) filename = ""; else filename = mgid + "_systemlog.html"; FileTarget FileList = new AdapterFile(new ImgAdapter()); Map valueCol = FileList.FolderList( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/", filename); File[] file = (File[]) valueCol.get("filename"); if (file != null) { int totle = file.length; Str.append("{\"total\":").append(totle).append(",\"rows\":["); int totlePage = 0; if (totle > 0) { if (totle % Integer.parseInt(PageSize) == 0) totlePage = totle / Integer.parseInt(PageSize); // 共有多少页 else totlePage = totle / Integer.parseInt(PageSize) + 1; int posion = ((Integer.parseInt(ShowPage) - 1) * Integer.parseInt(PageSize)) + 1; // 游标的位置 (当前页 - 1) * 页面大小 + 1 int endData = Integer.parseInt(PageSize) * Integer.parseInt(ShowPage); for (int i = posion; i <= totle; i++) { if (i <= endData) { Str.append("{") .append("\"filename\":") .append("\"") .append(file[i - 1].getName().split("\\.")[0]) .append("\"") .append(",") .append("\"filetime\":") .append("\"") .append( nowdate .centrum("yyyy-MM-dd HH:mm") .format(new Date(file[i - 1].lastModified()))) .append("\"") .append("}") .append(","); } } } else { Str.append("{") .append("\"filename\":") .append("\"\"") .append(",") .append("\"filetime\":") .append("\"\"") .append("}") .append(","); } } else { Str.append("{\"total\":").append(0).append(",\"rows\":["); Str.append("{") .append("\"filename\":") .append("\"\"") .append(",") .append("\"filetime\":") .append("\"\"") .append("}") .append(","); } Str.delete(Str.length() - 1, Str.length()); Str.append("]}"); out.print(Str.toString()); Str.delete(0, Str.length()); // 清空 } }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("content-type", "text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String UserStr = UserProxy.UserProxy(request); if (checkStr.isNull(UserStr)) { out.print("{\"err\":\"抱歉,您无权操作此模块\",\"msg\":\"\"}"); return; } String logmethod = tostr.to_utf_8(request.getParameter("logmethod")); if (logmethod.equals("clear")) // 清空 { if (checkStr.isNull(UserProxy.UserOptProxy(request, UserStr, "2"))) { out.print("{\"err\":\"抱歉,您无权操作此功能\",\"msg\":\"\"}"); return; } String logname = tostr.to_utf_8(request.getParameter("logname")); if (checkStr.isNull(logname)) { out.print("{\"err\":\"抱歉,请勿非法修改参数\",\"msg\":\"\"}"); return; } // 清空日志 Log.CreateFile( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/", logname + ".html", "<div style='width:100%;height:30px;line-height:30px;font-size:12px;border-bottom:solid 1px #000000;'>日志被 [" + UserStr.split(",")[1] + "]于" + nowdate.cu_datetime("yyyy-MM-dd HH:mm:ss") + "清空</div>\r\n", false); // 记录日志 Log.CreateFile( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/", UserStr.split(",")[0] + "_systemlog.html", "<div style='width:100%;height:30px;line-height:30px;font-size:12px;border-bottom:solid 1px #000000;'>用户 [" + UserStr.split(",")[1] + "]于" + nowdate.cu_datetime("yyyy-MM-dd HH:mm:ss") + "清空了名为 " + logname + " 的日志</div>\r\n" + Log.ReadFile( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/" + UserStr.split(",")[0] + "_systemlog.html"), false); out.print("{\"err\":\"\",\"msg\":\"日志清空成功\"}"); } else if (logmethod.equals("del")) // 删除 { if (checkStr.isNull(UserProxy.UserOptProxy(request, UserStr, "1"))) { out.print("{\"err\":\"抱歉,您无权操作此功能\",\"msg\":\"\"}"); return; } String logname = tostr.to_utf_8(request.getParameter("logname")); if (checkStr.isNull(logname)) { out.print("{\"err\":\"抱歉,请选择一条数据\",\"msg\":\"\"}"); return; } if (Log.FileDel( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/" + logname + ".html")) { // 记录日志 Log.CreateFile( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/", UserStr.split(",")[0] + "_systemlog.html", "<div style='width:100%;height:30px;line-height:30px;font-size:12px;border-bottom:solid 1px #000000;'>用户 [" + UserStr.split(",")[1] + "]于" + nowdate.cu_datetime("yyyy-MM-dd HH:mm:ss") + "删除了名为 " + logname + " 的日志</div>\r\n" + Log.ReadFile( request.getSession().getServletContext().getRealPath("/") + "Ds_admin/log/" + UserStr.split(",")[0] + "_systemlog.html"), false); out.print("{\"err\":\"\",\"msg\":\"日志删除成功\"}"); } else { out.print("{\"err\":\"抱歉,删除失败,请重试\",\"msg\":\"\"}"); } } else { out.print("{\"err\":\"请勿非法访问\",\"msg\":\"\"}"); } }