Operate_File.jsp
上传用户:zdly666
上传日期:2022-08-09
资源大小:6511k
文件大小:5k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ include file="conn.jsp"%>
  3. <%@page import="java.util.Date"%>
  4. <%@page import="java.util.*"%>
  5. <%@page import="java.text.*"%>
  6. <%@ page import ="java.io.* "%>
  7. <%@page import="com.oreilly.servlet.MultipartRequest"%>
  8. <html>
  9. <head>
  10. <title> </title>
  11. <link rel="stylesheet" type="text/css" href="file:///C|/Program Files/JSP/Tomcat 5.0/webapps/ROOT/Admin_Css/Admin_Style.css">
  12. </head>
  13. <body>
  14. <jsp:useBean id="pathtest" class="yu.beans.path_test" scope="page"/>
  15. <%
  16. String EditType=request.getParameter("EditType");//操作类别
  17. if(EditType==null||EditType.equals("null")||EditType.equals(""))
  18. {
  19. out.print("参数错误!");
  20. }else{
  21. if(EditType.equals("fileAdd"))
  22. {
  23. pathtest.initialize(pageContext);//初始化
  24. String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
  25. int maxSize=500*1024*1024;
  26. MultipartRequest  mult=new MultipartRequest(request,savaPath,maxSize,"GB2312");
  27. //out.println(savaPath);
  28. String column=mult.getParameter("Column_ID");
  29. String title=mult.getParameter("Title");
  30. String synopsis=mult.getParameter("Synopsis");
  31. String introduce=mult.getParameter("Introduce");
  32. String filename=mult.getOriginalFileName("File");
  33. Date currTime = new Date();
  34. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  35. String time=new String(formatter.format(currTime).getBytes("iso-8859-1"));
  36. String UploadSQL="insert into S_fileInfor(column_id,file_title,file_synopsis,file_introduce,file_date,file_name)values('"+column+"','"+title+"','"+synopsis+"','"+introduce+"','"+time+"','"+filename+"')";
  37. stmt.executeUpdate(UploadSQL);
  38. stmt.close(); 
  39. conn.close();
  40. out.print("<script>");
  41. out.print("alert('添加成功!');");
  42. out.print("window.location.href='Manage_File.jsp';");
  43. out.print("</script>");
  44. }
  45. if(EditType.equals("fileDel"))
  46. {
  47. String EditID=new String(request.getParameter("id").getBytes("ISO-8859-1"));//对应id
  48. if(EditID==null||EditID.equals("null"))
  49. {
  50. out.println("抱歉,参数出错!");
  51. }else{
  52. String FileName=new String(request.getParameter("file").getBytes("ISO-8859-1"));
  53. String DelFileSQL="delete from S_fileInfor where file_id='"+EditID+"'";//删除表中记录
  54. stmt.executeUpdate(DelFileSQL);
  55. //删除file
  56. pathtest.initialize(pageContext);//初始化
  57. String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
  58. File FileUped= new File(savaPath,FileName );
  59. boolean lzquan=FileUped.delete();
  60. stmt.close(); 
  61. conn.close();
  62. if(lzquan)
  63. {
  64. out.print("<script>");
  65. out.print("alert('删除成功!');");
  66. out.print("window.location.href='Manage_File.jsp';");
  67. out.print("</script>");
  68. }else{
  69. out.print("<script>");
  70. out.print("alert('删除失败!');");
  71. out.print("window.location.href='Manage_File.jsp';");
  72. out.print("</script>");
  73. }
  74. //response.sendRedirect("Manage_File.jsp");
  75. }
  76. }
  77. if(EditType.equals("fileEdit"))
  78. {
  79. //原文件名
  80. String FileName=new String(request.getParameter("file").getBytes("ISO-8859-1"));
  81. //对应id
  82. String EditID=new String(request.getParameter("id").getBytes("ISO-8859-1"));
  83. pathtest.initialize(pageContext);//初始化
  84. String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
  85. int maxSize=500*1024*1024;
  86. MultipartRequest mult=new MultipartRequest(request,savaPath,maxSize,"GB2312");
  87. String column=mult.getParameter("Column_ID");
  88. String title=mult.getParameter("Title");
  89. String date=mult.getParameter("Date");
  90. String synopsis=mult.getParameter("Synopsis");
  91. String introduce=mult.getParameter("Introduce");
  92. String filename=mult.getOriginalFileName("File");
  93. /* out.print(FileName+"    ");
  94. out.print(title+"    ");
  95. out.print(synopsis+"    ");
  96. out.print(introduce+"    ");
  97. out.print(filename+" filename   ");*/
  98. if(filename==null||filename.equals("null")||FileName.compareTo(filename)==0)
  99. {
  100. String EditSQL1="update S_fileInfor set file_title='"+title+"',file_synopsis='"+synopsis+"',file_introduce='"+introduce+"',file_date='"+date+"' where file_id='"+EditID+"'";
  101. //out.print(EditSQL1);
  102. stmt.executeUpdate(EditSQL1);
  103. }else{
  104. String EditSQL2="update S_fileInfor set file_title='"+title+"',file_synopsis='"+synopsis+"',file_introduce='"+introduce+"',file_date='"+date+"',file_name='"+filename+"' where file_id='"+EditID+"'";
  105. //out.print(EditSQL2);
  106. stmt.executeUpdate(EditSQL2);
  107. File FileUped= new File(savaPath,FileName );
  108. boolean lzquan=FileUped.delete();
  109. }
  110. stmt.close();
  111. conn.close();
  112. out.print("<script>");
  113. out.print("alert('修改成功!');");
  114. out.print("window.location.href='Manage_File.jsp';");
  115. out.print("</script>");
  116. }
  117. }
  118. %>
  119. </body>
  120. </html>