上傳文件到服務器:
頁面:
代碼:
注意點1:
頁面表單要加上: enctype=”multipart/form-data”
web.xml 配置:要在對應的表單提交路徑下
注意點2:String file=req.getParameter(“file”); 拿不到文件名
注意點3:拿文件名時:
String header = part.getHeader(“content-disposition”);
header的內容如下:通過頭的名稱content-disposition拿filename
注意點4:Part part=req.getPart(“file”);
tomcat服務器版本低沒這個Part接口
part.getName() 這個方法拿的不是文件名,是表單中爲文件表單取的名字