upload.jsp~75~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:5k
源码类别:
OA系统
开发平台:
Java
- <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
- <%@ page import="com.jspsmart.upload.*,officeol.mc.tools.*"%>
- <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
- <%request.setCharacterEncoding("GBK"); %>
- <html>
- <head>
- <title>上载附件 </title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- </head>
- <body>
- <center>
- <%
- String message = request.getAttribute("msg")==null?"":request.getAttribute("msg").toString();
- out.print(message);
- String ud = (String)session.getAttribute("UD");
- String udid = (String)session.getAttribute("UDID");
- String un = (String)session.getAttribute("UN");
- String uid = (String)session.getAttribute("UID");
- String pp = (String)session.getAttribute("POPE");
- String login = (String)session.getAttribute("LOGIN");
- String wjm = (String)session.getAttribute("wjm");
- String sm = (String)session.getAttribute("sm");
- String ft = (String)session.getAttribute("ft");
- PopedomCheck pc = new PopedomCheck();
- //上载附件
- Date date = new java.sql.Date(new java.util.Date().getTime());
- String dates = ""+date;
- try{
- Tool tl = new Tool();
- //out.print(tl.getTime());
- String tt = tl.getTime();
- DBConn dbc = new DBConn();
- if(wjm==null||wjm.equals("")){
- out.print("上传文件名不能为请,请重新填写再上传!");
- %><a href=fileupload1.jsp>重新上传</a>
- <%
- }else{
- mySmartUpload.initialize(pageContext);
- mySmartUpload.service(request,response);
- // 设定上传限制
- // 1.限制每个上传文件的最大长度。
- // mySmartUpload.setMaxFileSize(10000);
- // 2.限制总上传数据的长度。
- // mySmartUpload.setTotalMaxFileSize(20000);
- // 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
- // mySmartUpload.setAllowedFilesList("doc,txt");
- // 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,jsp,htm,html扩展名的文件和没有扩展名的文件。
- mySmartUpload.setDeniedFilesList("exe,bat,,");
- mySmartUpload.upload();
- String fn=mySmartUpload.getFiles().getFile(0).getFileName();
- String tempfn = tt+"."+mySmartUpload.getFiles().getFile(0).getFileExt();
- //mySmartUpload.save("upload/");//文件保存的目录为upload
- String sql = "insert into files (files.filename,uptime,upuserid,fileexplan,upuserdeparid,savename,filetype) "+
- "values('"+wjm+"','"+dates+"','"+uid+"','"+sm+"','"+udid+"','"+tempfn+"',"+ft+")";
- dbc.executeUpdate(sql);
- for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
- com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);
- // 若文件不存在则继续
- if (file.isMissing()) continue;
- String saname = tt;
- //out.print(file.getFileExt());
- String ext = file.getFileExt();
- saname = tt+"."+ext;
- // 显示当前文件信息out.print(saname);
- out.println("<TABLE BORDER=1 width="50%">");
- out.println("<TR><TD>上传文件</TD><TD>"+ wjm + "</TD></TR>");
- out.println("<TR><TD>文件长度</TD><TD>" +
- file.getSize() + "</TD></TR>");
- out.println("<TR><TD>文件名</TD><TD>"
- + file.getFileName() + "</TD></TR>");
- out.println("<TR><TD>文件说明</TD><TD>"+ sm + "</TD></TR>");
- out.println("<TR><TD>上传时间</TD><TD>"+ dates + "</TD></TR>");
- //out.println("<TR><TD>文件另存为名(SaveAsName)</TD><TD>"+ saname + "</TD></TR>");
- out.println("</TABLE><BR>");
- // 将文件另存
- file.saveAs("/upload/" + saname);
- // 另存到以WEB应用程序的根目录为文件根目录的目录下
- // file.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL);
- // 另存到操作系统的根目录为文件根目录的目录下
- // file.saveAs("c:\temp\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);
- }
- // 利用Request对象获取参数之值
- //out.println("TEST="+mySmartUpload.getRequest().getParameter("TEST") +"<BR><BR>");
- //request.setAttribute("fn",fn);
- //session.setAttribute("fna",fn);
- out.print(fn);
- out.println("已经成功上传了文件,请查看<a href=download.jsp?fn="+tt+fn+">这里</a>,看文件是否上传成功");
- session.removeAttribute("wjm");
- session.removeAttribute("sm");
- session.removeAttribute("ft");
- }
- }catch(java.lang.SecurityException se){
- out.print("系统不允许上传文件扩展名为.exe .bat以及无扩展名文件");
- }catch(Exception e){
- e.printStackTrace();
- }
- %>
- <a href=fileupload1.jsp>重新上传</a>
- </body>
- </html>