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

📄 upload.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:   Upload.java

package com.cwc.util;

import com.jspsmart.upload.*;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.jsp.PageContext;

public class Upload
{

    private HashMap fileNames;
    private ArrayList fileSize;
    private ArrayList fileExtend;
    private ArrayList filePath;
    private String uploadPath;
    private int uploadCount;
    private SmartUpload smartUpload;
    private String permitUpFile;
    int permitFileSize;
    String filename;

    public Upload()
    {
        fileNames = new HashMap();
        fileSize = new ArrayList();
        fileExtend = new ArrayList();
        filePath = new ArrayList();
        uploadPath = null;
        uploadCount = 0;
        filename = null;
        smartUpload = new SmartUpload();
    }

    public String save()
        throws Exception
    {
        String exceptionPath = "";
        try
        {
            String msg = "";
            smartUpload.upload();
            uploadCount = smartUpload.getFiles().getCount();
            for(int i = 0; i < uploadCount; i++)
            {
                File uploadFile = smartUpload.getFiles().getFile(i);
                if(uploadFile.isMissing())
                    continue;
                if(getPermitUpFile().indexOf(uploadFile.getFileExt().toLowerCase()) == -1)
                {
                    msg = uploadFile.getFileExt() + " 不在允许上传的文件类型:" + getPermitUpFile() + " 范围内";
                    break;
                }
                if(uploadFile.getSize() > getPermitFileSize())
                {
                    msg = "文件大小 " + uploadFile.getSize() + " 超过 " + getPermitFileSize() + " 规定范围";
                    break;
                }
                String defFileName = getDefFileName();
                exceptionPath = uploadPath + defFileName + String.valueOf(i) + "." + uploadFile.getFileExt();
                uploadFile.saveAs(exceptionPath);
                fileNames.put(uploadFile.getFieldName(), defFileName + String.valueOf(i) + "." + uploadFile.getFileExt());
                fileSize.add(new Integer(uploadFile.getSize()));
                fileExtend.add(uploadFile.getFileExt());
                filePath.add(uploadFile.getFilePathName());
            }

            return msg;
        }
        catch(Exception e)
        {
            throw new ServletException("save(" + exceptionPath + ")" + e);
        }
    }

    public String saveAsSameName()
        throws Exception
    {
        String exceptionPath = "";
        try
        {
            String msg = "";
            smartUpload.upload();
            uploadCount = smartUpload.getFiles().getCount();
            for(int i = 0; i < uploadCount; i++)
            {
                File uploadFile = smartUpload.getFiles().getFile(i);
                if(uploadFile.isMissing())
                    continue;
                if(getPermitUpFile().indexOf(uploadFile.getFileExt().toLowerCase()) == -1)
                {
                    msg = uploadFile.getFileExt() + " 不在允许上传的文件类型:" + getPermitUpFile() + " 范围内";
                    break;
                }
                if(uploadFile.getSize() > getPermitFileSize())
                {
                    msg = "文件大小 " + uploadFile.getSize() + " 超过 " + getPermitFileSize() + " 规定范围";
                    break;
                }
                String defFileName;
                if(getFileName() != null)
                    defFileName = getFileName();
                else
                    defFileName = uploadFile.getFileName();
                exceptionPath = uploadPath + defFileName;
                uploadFile.saveAs(exceptionPath);
                fileNames.put(uploadFile.getFieldName(), defFileName);
                fileSize.add(new Integer(uploadFile.getSize()));
                fileExtend.add(uploadFile.getFileExt());
                filePath.add(uploadFile.getFilePathName());
            }

            return msg;
        }
        catch(Exception e)
        {
            throw new ServletException("save(" + exceptionPath + ")" + e);
        }
    }

    private String getDefFileName()
    {
        if(getFileName() != null)
        {
            return getFileName();
        } else
        {
            long time = (new Date()).getTime();
            return String.valueOf(time);
        }
    }

    public void setPageContext(PageContext p)
        throws ServletException
    {
        try
        {
            smartUpload.initialize(p);
        }
        catch(ServletException e)
        {
            throw new ServletException("setPageContext(" + p + ")" + e.getMessage());
        }
    }

    public void setUploadPath(String string)
    {
        uploadPath = string;
    }

    public String getUploadPath()
    {
        return uploadPath;
    }

    public String getString(String key)
    {
        if(smartUpload.getRequest().getParameter(key) == null)
            return "";
        else
            return smartUpload.getRequest().getParameter(key);
    }

    public int getInt(String key)
    {
        int t;
        try
        {
            t = (new Integer(smartUpload.getRequest().getParameter(key))).intValue();
        }
        catch(NumberFormatException e)
        {
            t = 0;
        }
        return t;
    }

    public float getFloat(String key)
    {
        float t = 0.0F;
        if(smartUpload.getRequest().getParameter(key) == null)
            return 0.0F;
        try
        {
            t = Float.parseFloat(smartUpload.getRequest().getParameter(key));
        }
        catch(NumberFormatException numberformatexception) { }
        return t;
    }

    public ArrayList getFileExtend()
    {
        return fileExtend;
    }

    public HashMap getFileNames()
    {
        return fileNames;
    }

    public ArrayList getFilePath()
    {
        return filePath;
    }

    public ArrayList getFileSize()
    {
        return fileSize;
    }

    public String getPermitUpFile()
    {
        return permitUpFile;
    }

    public void setPermitUpFile(String string)
    {
        permitUpFile = string;
    }

    public int getPermitFileSize()
    {
        return permitFileSize;
    }

    public void setPermitFileSize(int i)
    {
        permitFileSize = i;
    }

    public String getFileName()
    {
        return filename;
    }

    public void setFileName(String fn)
    {
        filename = fn;
    }
}

⌨️ 快捷键说明

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