servlet 中使用smartupload 组件

 response.setContentType("text/html;charset=gb2312");
      PrintWriter out = response.getWriter();
         SmartUpload mySmartUpload = new SmartUpload();
     String currentDirectoryPath=null;
     String savePath="E:/public_html/java_root/NETDISK/WebRoot/NET_SPACE/1/我的音乐/";
          //mySmartUpload.setDenyPhysicalPath(true);
          mySmartUpload.setForcePhysicalPath(true);
           mySmartUpload.initialize(this.getServletConfig(), request,response);
           // 设定上传限制
           // 1.限制每个上传文件的最大长度。10M
           mySmartUpload.setMaxFileSize(10000000);
          
           // 2.限制总上传数据的长度。
          
           // mySmartUpload.setTotalMaxFileSize(20000);
          
           // 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
          
           // mySmartUpload.setAllowedFilesList("doc,txt");
          
           // 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文件和没有扩展名的文件。
          
           // mySmartUpload.setDeniedFilesList("exe,bat,jsp,htm,html,,");
         // Deny physical path
         
          
           try {
       mySmartUpload.upload();
      } catch (SmartUploadException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
      }
          
           //读取其它数据
          
           com.jspsmart.upload.Request req = mySmartUpload.getRequest();
          
           String title = req.getParameter("dest");
          
           //保存文件
           for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
          
           com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);
          
           if (file.isMissing()) continue;
           try {
       file.saveAs(savePath+file.getFileName());
      } catch (SmartUploadException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       logger.info("e:"+e);
      }
          
           }        
            out.println("dest:"+title);
      out.close();  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值