//設(shè)置上傳文件保存路徑
String?filePath?=?getServletContext().getRealPath("/")?+?"images";
System.out.println(filePath);
File?file?=?new?File(filePath);
if?(!file.exists())?{
file.mkdirs();
}
SmartUpload?su?=?new?SmartUpload();
//初始化對象
su.initialize(getServletConfig(),?request,?response);
//設(shè)置上傳文件大小
su.setMaxFileSize(1024*1024*10);//為10M
//設(shè)置所有文件的大小
su.setTotalMaxFileSize(1024*1024*100);//為100M
//設(shè)置允許上傳文件類型
su.setAllowedFilesList("txt,jpg,gif,mp3");
String?result?=?"上傳成功";
//設(shè)置禁止上傳文件類型
try?{
su.setDeniedFilesList("rar,jsp,sj");
//上傳文件
su.upload();
int?count?=?su.save(filePath);
System.out.println("上傳成功"?+?count?+?"個文件!");
}?catch?(Exception?e)?{
result?=?"上傳失敗";
e.printStackTrace();
}
request.setAttribute("result",?result);
request.getRequestDispatcher("02.jsp").forward(request,?response);
}
protected?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)
throws?ServletException,?IOException?{
doGet(request,?response);
}
2017-07-06
去相應的你的這個發(fā)布目錄找一下E:\javaEE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UploadandDownload
2017-10-18
你這個問題解決了沒,怎么解決的啊,求告知
2017-09-14
可以檢查一下jsp頁面中,表單中input file 中是否有name屬性,沒有的話就上傳不了