文件上传servlet应用

    技术2022-05-20  41

    SmartUpload mySmartUpload = new SmartUpload();  mySmartUpload.initialize(servlet.getServletConfig(), request,response);  // 设定上传限制  // 1.限制每个上传文档的最大长度。   mySmartUpload.setMaxFileSize(2*1024*1024);  //单个上传文件不超过2M  // 2.限制总上传数据的长度。   mySmartUpload.setTotalMaxFileSize(10*1024*1024);  //总上传文件不超过10M  // 3.设定允许上传的文档(通过扩展名限制),仅允许doc,txt文档。   mySmartUpload.setAllowedFilesList("doc,txt");  // 4.设定禁止上传的文档(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文档和没有扩展名的文档。   mySmartUpload.setDeniedFilesList("exe,bat,jsp,htm,html,,");  mySmartUpload.upload();  //读取其他数据  Request req = mySmartUpload.getRequest();  String title = req.getParameter("title");  //保存文档  for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {  com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);  if (file.isMissing()) continue;  file.saveAs(savePath + file.getFileName());  }


    最新回复(0)