do_upload.jsp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <%@page import="java.util.Date"%>
  2. <%@page import="java.text.SimpleDateFormat"%>
  3. <%@page import="org.springframework.http.HttpStatus"%>
  4. <%@page import="com.uas.cr.util.HttpUtil.Response"%>
  5. <%@page import="com.uas.cr.util.FlexJsonUtil"%>
  6. <%@page import="java.util.ArrayList"%>
  7. <%@page import="java.util.HashMap"%>
  8. <%@page import="java.util.Map"%>
  9. <%@page import="com.uas.cr.util.HttpUtil"%>
  10. <%@ page import="com.jspsmart.upload.File"%>
  11. <%@ page import="com.jspsmart.upload.SmartUpload"%>
  12. <%@ page import="java.util.List"%>
  13. <%@ page import="java.sql.PreparedStatement"%>
  14. <%@ page import="java.sql.Connection"%>
  15. <%@ page import="com.uas.cr.util.DBConnection"%>
  16. <%@ page language="java" contentType="text/html; charset=UTF-8"
  17. pageEncoding="UTF-8"%>
  18. <%@ page import="com.uas.cr.util.FileUtil"%>
  19. <%@ page import="java.net.URLEncoder"%>
  20. <%@ page import="java.io.*"%>
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  22. <html>
  23. <head>
  24. <meta http-equiv="content-Type" contentType="text/html;charset=UTF-8">
  25. <link rel="shortcut icon" type="image/x-icon" href="img/u.png" />
  26. <title>上传</title>
  27. </head>
  28. <body>
  29. <%try {
  30. SmartUpload su = new SmartUpload();
  31. su.initialize(pageContext);
  32. su.service(request, response);
  33. su.setTotalMaxFileSize(100000000);
  34. su.upload();
  35. String uu = su.getRequest().getParameter("uu");
  36. String reportBusi = su.getRequest().getParameter("reportBusi");
  37. String description = su.getRequest().getParameter("description");
  38. String reportPageName = su.getRequest().getParameter("reportPageName");
  39. String name = su.getRequest().getParameter("userName");
  40. File suFile = su.getFiles().getFile(0);
  41. String fileName = suFile.getFilePathName();
  42. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd H-m-s");
  43. String date = sdf.format(new Date());
  44. if (!suFile.isMissing()) {
  45. String realPath = application.getRealPath(request.getRequestURI());
  46. java.io.File transFile = new java.io.File(realPath);
  47. realPath = transFile.getParentFile().getParentFile().getParentFile().getPath() + "/rpt";
  48. String backupPath = transFile.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile().getPath() + "/rpt";
  49. java.io.File fileTemp = new java.io.File(realPath);
  50. java.io.File backupfileTemp = new java.io.File(backupPath);
  51. if (!fileTemp.exists()) {
  52. fileTemp.mkdir();
  53. }
  54. if (!backupfileTemp.exists()) {
  55. backupfileTemp.mkdir();
  56. }
  57. realPath = realPath + "/" + uu;
  58. backupPath = backupfileTemp + "/" + uu;
  59. fileTemp = new java.io.File(realPath);
  60. backupfileTemp = new java.io.File(backupPath);
  61. if (!fileTemp.exists()) {
  62. fileTemp.mkdir();
  63. }
  64. if (!backupfileTemp.exists()) {
  65. backupfileTemp.mkdir();
  66. }
  67. realPath = realPath + "/";
  68. backupPath = backupPath + "/";
  69. backupPath = backupPath +date+ suFile.getFilePathName();
  70. realPath = realPath + suFile.getFilePathName();
  71. fileTemp = new java.io.File(realPath);
  72. DBConnection db = new DBConnection();
  73. Connection con = db.createCon();
  74. PreparedStatement pre = null;
  75. if(fileTemp.exists()) {
  76. pre = con.prepareStatement("update REPORT$CONFIG set RE_PAGENAME= ? where RE_ENUU= ? and RE_REPORTNAME= ?");
  77. pre.setString(1, reportPageName);
  78. pre.setLong(2, Long.parseLong(uu));
  79. pre.setString(3, suFile.getFilePathName());
  80. }else {
  81. pre = con.prepareStatement(
  82. "insert into REPORT$CONFIG(RE_ID, RE_ENUU, RE_REPORTNAME, RE_PAGENAME) values (REPORT$CONFIG_seq.nextval, ?, ?, ?)");
  83. pre.setLong(1, Long.parseLong(uu));
  84. pre.setString(2, suFile.getFilePathName());
  85. pre.setString(3, reportPageName);
  86. }
  87. suFile.saveAs(realPath);
  88. suFile.saveAs(backupPath);
  89. pre.executeUpdate();
  90. Map<String, String> map = new HashMap<String, String>();
  91. List<Map<String, String>> list = new ArrayList<Map<String, String>>();
  92. map.put("enuu", uu);
  93. map.put("reportBusi", reportBusi);
  94. map.put("description", description);
  95. map.put("fileName", fileName);
  96. map.put("name", name);
  97. list.add(map);
  98. String data = FlexJsonUtil.toJsonArrayDeep(list);
  99. Map<String, String> mapFile = new HashMap<String, String>();
  100. mapFile.put("data", data);
  101. com.uas.cr.util.HttpUtil.Response res = HttpUtil.sendPostRequest(
  102. "http://10.10.100.81:8080/public/upReport/message", mapFile, true);
  103. out.println("文件上传成功,请刷新管理台页面! ");
  104. if((pre != null)&&(!pre.isClosed())) {
  105. pre.close();
  106. }
  107. if(db != null) {
  108. db.closeCon(con);
  109. }
  110. }
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. out.println("上传文件失败!报错信息:");
  114. out.println(e.getMessage());
  115. }%>
  116. </body>
  117. </html>