⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadfile.java

📁 java版的发送电子邮件组件
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   UploadFile.java

package dispose;

import com.jspsmart.upload.Files;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.zyf.tools.connectdb.DBOS;
import java.io.File;
import java.io.FileInputStream;
import java.sql.PreparedStatement;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

public class UploadFile
{

    public String allowedType;
    public int maxFileSize;
    public String fileName;
    public String fileExt;
    public String fileContentType;
    public int fileSize;
    public String sessionId;
    public SmartUpload mySmartUpload;

    public void setAllowedType(String s)
    {
        allowedType = s;
        mySmartUpload.setAllowedFilesList(s);
    }

    public String getAllowedType()
    {
        return allowedType;
    }

    public void setMaxFileSize(int i)
    {
        maxFileSize = i;
        mySmartUpload.setMaxFileSize(i);
    }

    public int getMaxFileSize()
    {
        return maxFileSize;
    }

    public String getFileName()
    {
        fileName = mySmartUpload.getFiles().getFile(0).getFileName();
        return fileName;
    }

    public String getFileExt()
    {
        fileExt = mySmartUpload.getFiles().getFile(0).getFileExt();
        fileExt = fileExt.toLowerCase();
        return fileExt;
    }

    public String getFileContentType()
    {
        fileContentType = mySmartUpload.getFiles().getFile(0).getContentType();
        fileContentType = fileContentType.trim();
        return fileContentType;
    }

    public int getFileSize()
    {
        fileSize = mySmartUpload.getFiles().getFile(0).getSize();
        return fileSize;
    }

    public UploadFile()
    {
        allowedType = "";
        maxFileSize = 0x500000;
        fileName = "";
        fileExt = "";
        fileContentType = "";
        sessionId = "";
        mySmartUpload = new SmartUpload();
    }

    public void initialize(PageContext pagecontext)
        throws Exception
    {
        mySmartUpload.initialize(pagecontext);
        mySmartUpload.upload();
        sessionId = pagecontext.getSession().getId();
    }

    public void initialize(ServletConfig servletconfig, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws Exception
    {
        mySmartUpload.initialize(servletconfig, httpservletrequest, httpservletresponse);
        mySmartUpload.upload();
        sessionId = httpservletrequest.getSession().getId();
    }

    public String getParameter(String s)
        throws Exception
    {
        String s1 = "";
        s1 = mySmartUpload.getRequest().getParameter(s);
        return s1;
    }

    public Enumeration getParameterNames()
        throws Exception
    {
        return mySmartUpload.getRequest().getParameterNames();
    }

    public String[] getParameterValues(String s)
        throws Exception
    {
        return mySmartUpload.getRequest().getParameterValues(s);
    }

    public void uploadFileToDB(String s)
        throws Exception
    {
        mySmartUpload.getFiles().getFile(0).saveAs("/" + sessionId + "." + getFileExt(), 0);
        String s1 = "/Tomcat/webapps/ROOT/" + sessionId + "." + getFileExt();
        File file = new File(s1);
        DBOS dbos = new DBOS();
        try
        {
            if(s != null && !s.equals(""))
            {
                if(s.toUpperCase().startsWith("INSERT"))
                    if(fileSize <= maxFileSize)
                    {
                        dbos.prepareStatement(s);
                        FileInputStream fileinputstream = new FileInputStream(file);
                        dbos.pstmt.setBinaryStream(1, fileinputstream, fileSize);
                        dbos.pstmt.executeUpdate();
                        fileinputstream.close();
                    } else
                    {
                        throw new Exception("文件太大!");
                    }
            } else
            {
                throw new Exception("不是INSERT语句!");
            }
        }
        catch(Exception exception)
        {
            throw exception;
        }
        finally
        {
            dbos.releaseResource();
        }
        file.delete();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -