1 @RequestMapping("fileDelete") 3 public void fileDelete(HttpServletRequest request, HttpServletResponse response) throws IOException { 4 String filepath = URLDecoder.decode(RequestUtil.getString(request, "selcurFile")); 5 String configPath1 = ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("/"); 6 String filePath = configPath1 + filepath; 7 try { 8 // 判断文件是否存在,创建文件 9 File file = new File(filePath); 10 if (!file.exists()) { 11 StringBuilder gridJson = new StringBuilder(); 12 gridJson.append("{\"result\":"); 13 gridJson.append("2"); 14 gridJson.append(",\"message\":"); 15 gridJson.append("\"文件不存在!\""); 20 gridJson.append("}"); 21 PrintWriter out = response.getWriter(); 22 out.print(gridJson.toString()); 23 } else { 24 FileUtil.deleteFile(filePath); 25 StringBuilder gridJson = new StringBuilder(); 26 gridJson.append("{\"result\":"); 27 gridJson.append("1"); 28 gridJson.append(",\"message\":"); 29 gridJson.append("\"文件删除成功!\""); 34 gridJson.append("}"); 35 PrintWriter out = response.getWriter(); 36 out.print(gridJson.toString()); 37 } 38 } catch (Exception e) { 39 StringBuilder gridJson = new StringBuilder(); 40 gridJson.append("{\"result\":"); 41 gridJson.append("0"); 42 gridJson.append(",\"message\":"); 43 gridJson.append("\"文件删除失败!\""); 44 gridJson.append("}"); 45 PrintWriter out = response.getWriter(); 46 out.print(gridJson.toString()); 47 return; 48 } 49 }