jsp上传文件

来源:互联网 发布:网络电影女主角 编辑:程序博客网 时间:2024/06/09 19:23

  Date d=new Date();
       SimpleDateFormat aa = new SimpleDateFormat("yyyyMMdd-HHmmss");
   SmartUpload fileup= new SmartUpload();
   fileup.initialize(pageContext);  // 上传初始化
         fileup.setAllowedFilesList("jpg,gif,jpeg");//允许jpg,gif,jpeg文件。
    fileup.setDeniedFilesList("exe,bat,jsp,htm,html,,");// 设定禁止上传的文件
    fileup.upload();// 上传图片
     String realurl="images/";
    fileup.save(realurl);//保存到指定目录
   //========================
    String ext ="";
   com.jspsmart.upload.File myFile = fileup.getFiles().getFile(0);
             ext= myFile.getFileExt(); //取得后缀名
            String filename=aa.format(d);
            String myphoto=filename+"."+ext;//把时间作为文件名
   String realpath=realurl+myphoto;
   myFile.saveAs(realpath);

原创粉丝点击