---
title: "SmartUpload在servlet中使用方法"
author: "piperzero"
date: "2005-09-08T10:14:00Z"
tags: []
slug: "smartupload-servlet"
draft: false
lastmod: "2013-02-21T19:53:44Z"
id: 1811657
url: "https://piperzero.iteye.com/blog/1811657"
---

SmartUpload mySmartUpload = new SmartUpload();  
mySmartUpload.initialize(getServletConfig(), request,response);  
// 设定上传限制  
// 1.限制每个上传文件的最大长度。  
// mySmartUpload.setMaxFileSize(10000);  
// 2.限制总上传数据的长度。  
// mySmartUpload.setTotalMaxFileSize(20000);  
// 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 &lt; mySmartUpload.getFiles().getCount(); i++) {  
com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);  
if (file.isMissing()) continue;  
file.saveAs(savePath + file.getFileName());  
}