Operate_File.jsp
资源名称:zyp.rar [点击查看]
上传用户:zdly666
上传日期:2022-08-09
资源大小:6511k
文件大小:5k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
- <%@ include file="conn.jsp"%>
- <%@page import="java.util.Date"%>
- <%@page import="java.util.*"%>
- <%@page import="java.text.*"%>
- <%@ page import ="java.io.* "%>
- <%@page import="com.oreilly.servlet.MultipartRequest"%>
- <html>
- <head>
- <title> </title>
- <link rel="stylesheet" type="text/css" href="file:///C|/Program Files/JSP/Tomcat 5.0/webapps/ROOT/Admin_Css/Admin_Style.css">
- </head>
- <body>
- <jsp:useBean id="pathtest" class="yu.beans.path_test" scope="page"/>
- <%
- String EditType=request.getParameter("EditType");//操作类别
- if(EditType==null||EditType.equals("null")||EditType.equals(""))
- {
- out.print("参数错误!");
- }else{
- if(EditType.equals("fileAdd"))
- {
- pathtest.initialize(pageContext);//初始化
- String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
- int maxSize=500*1024*1024;
- MultipartRequest mult=new MultipartRequest(request,savaPath,maxSize,"GB2312");
- //out.println(savaPath);
- String column=mult.getParameter("Column_ID");
- String title=mult.getParameter("Title");
- String synopsis=mult.getParameter("Synopsis");
- String introduce=mult.getParameter("Introduce");
- String filename=mult.getOriginalFileName("File");
- Date currTime = new Date();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- String time=new String(formatter.format(currTime).getBytes("iso-8859-1"));
- 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+"')";
- stmt.executeUpdate(UploadSQL);
- stmt.close();
- conn.close();
- out.print("<script>");
- out.print("alert('添加成功!');");
- out.print("window.location.href='Manage_File.jsp';");
- out.print("</script>");
- }
- if(EditType.equals("fileDel"))
- {
- String EditID=new String(request.getParameter("id").getBytes("ISO-8859-1"));//对应id
- if(EditID==null||EditID.equals("null"))
- {
- out.println("抱歉,参数出错!");
- }else{
- String FileName=new String(request.getParameter("file").getBytes("ISO-8859-1"));
- String DelFileSQL="delete from S_fileInfor where file_id='"+EditID+"'";//删除表中记录
- stmt.executeUpdate(DelFileSQL);
- //删除file
- pathtest.initialize(pageContext);//初始化
- String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
- File FileUped= new File(savaPath,FileName );
- boolean lzquan=FileUped.delete();
- stmt.close();
- conn.close();
- if(lzquan)
- {
- out.print("<script>");
- out.print("alert('删除成功!');");
- out.print("window.location.href='Manage_File.jsp';");
- out.print("</script>");
- }else{
- out.print("<script>");
- out.print("alert('删除失败!');");
- out.print("window.location.href='Manage_File.jsp';");
- out.print("</script>");
- }
- //response.sendRedirect("Manage_File.jsp");
- }
- }
- if(EditType.equals("fileEdit"))
- {
- //原文件名
- String FileName=new String(request.getParameter("file").getBytes("ISO-8859-1"));
- //对应id
- String EditID=new String(request.getParameter("id").getBytes("ISO-8859-1"));
- pathtest.initialize(pageContext);//初始化
- String savaPath=pathtest.getPhysicalPath("/zyp/file/",0);//传参数
- int maxSize=500*1024*1024;
- MultipartRequest mult=new MultipartRequest(request,savaPath,maxSize,"GB2312");
- String column=mult.getParameter("Column_ID");
- String title=mult.getParameter("Title");
- String date=mult.getParameter("Date");
- String synopsis=mult.getParameter("Synopsis");
- String introduce=mult.getParameter("Introduce");
- String filename=mult.getOriginalFileName("File");
- /* out.print(FileName+" ");
- out.print(title+" ");
- out.print(synopsis+" ");
- out.print(introduce+" ");
- out.print(filename+" filename ");*/
- if(filename==null||filename.equals("null")||FileName.compareTo(filename)==0)
- {
- String EditSQL1="update S_fileInfor set file_title='"+title+"',file_synopsis='"+synopsis+"',file_introduce='"+introduce+"',file_date='"+date+"' where file_id='"+EditID+"'";
- //out.print(EditSQL1);
- stmt.executeUpdate(EditSQL1);
- }else{
- 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+"'";
- //out.print(EditSQL2);
- stmt.executeUpdate(EditSQL2);
- File FileUped= new File(savaPath,FileName );
- boolean lzquan=FileUped.delete();
- }
- stmt.close();
- conn.close();
- out.print("<script>");
- out.print("alert('修改成功!');");
- out.print("window.location.href='Manage_File.jsp';");
- out.print("</script>");
- }
- }
- %>
- </body>
- </html>