可以使用smartupload上传
jsp代码:
<form name="frm" method="post"  action="<%=request.getContextPath()%>/checkValue" enctype="multipart/form-data">
<tr>
<td>上传文件:</td>
<td><input type="file" name="uploadFile"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="确定"></td>
</tr>
</form>
enctype="multipart/form-data"这个一定要的后台servlet:
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
SmartUpload upload = new SmartUpload();

//初始化数据
upload.initialize(this.getServletConfig(),arg0,arg1);
//设置每个上传文件的大小
upload.setMaxFileSize(1028*10);
//设置所有上传文件的总大小
upload.setTotalMaxFileSize(1028*10*10);
//设置上传文件的类型
upload.setAllowedFilesList("doc,txt,xls");


try{
//设置禁止上传的文件类型
upload.setDeniedFilesList("exe,rar,bat");
upload.upload(); //保存文件
Files files= upload.getFiles();
System.out.println("files count:"+files.getCount());
for(int i=0;i<files.getCount();i++){
File file = files.getFile(i);
if(file.isMissing()) continue;
file.saveAs("e:\\"+file.getFileName());
}
PrintWriter out = arg1.getWriter();
out.println("<script>alert('success');</script>");
out.flush();
out.close();
} catch (Exception e) {



}