05、攔截器與檔案上傳
阿新 • • 發佈:2018-11-12
Interceptor
implements Interceptor
extends AbstractInterceptor
與filter的區別:先過filter再過interceptor
檔案上傳:
三種上傳方案
虛擬路徑與真實路徑 /upload
copyFile與copydirectory
0. 檔案下載
另存為
直接開啟
-
內容型別
response.setContentType(d.getMime()); -
設定響應頭
response.setHeader(“Content-Disposition”,“attachment;filename=” + fileName);//檔名 -
處理檔名的中文亂碼
String fileName = d.getFileName();
fileName = new String(fileName.getBytes(“utf-8”), “iso8859-1”); -
struts2檔案上傳大小設定
-
struts2檔案上傳型別設定
image/png,image/gif,image/jpeg
根據struts2自帶的fileupload攔截器中提供的allowedTypes來進行限制
-
其它
enctype=“multipart/form-data” method=“post”
private File file;
private String fileContentType;
private String fileFileName;org.apache.struts2.interceptor.FileUploadInterceptor