当前位置: 首页 > 工具软件 > UploadBean > 使用案例 >

uploadBean

宋宏儒
2023-12-01

package com.test.upload;

import org.apache.commons.fileupload.*;
import org.apache.commons.io.*;

import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import javax.servlet.http.HttpServletRequest;

public class Upload {
 
 HttpServletRequest request;
 String dir="";
 
 
 public Upload(HttpServletRequest request)
 {
     this.request=request;
     dir=request.getRealPath("");
 }
 
 public void upload() throws Exception
 {
     DiskFileUpload dfu=new DiskFileUpload();
        List fileItems=dfu.parseRequest(request,4096,4194304,dir+"//test");
        Iterator it=fileItems.iterator();
        while(it.hasNext())
        {
            FileItem f=(FileItem)it.next();
            String key="";
            if(f.isFormField())
            {
                key=f.getFieldName();

            } 
            else
            {
                String fileName=f.getName();
                Date date=new Date();
                SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd");
                String d=sdf.format(date);
                if(fileName!=null)
                {
                    f.write(new File(dir+"//test//"+d+".jpg"));
                }
            }
       
          }//while
     }
 
}
 

 类似资料:

相关阅读

相关文章

相关问答