下载 中文名称的文件 struts报错
<a href="download.action?filename=123图片.jpg">文件下载</a> <action name="download" class="com.pactera.action.FileDownloadAction"> <!-- <param name="inputPath">/</param> --> <result name="success" type="stream"> <param name="contentType">application/octet-stream</param> <param name="inputName">inputStream</param> <param name="contentDisposition">attachment;filename="${downloadFileName}"</param> <param name="bufferSize">8192</param> </result> </action>
String filename;
public String getDownloadFileName() {
String downloadFileName = "";
try {
downloadFileName = URLEncoder.encode(filename,"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return downloadFileName;
}
public InputStream getInputStream() throws IOException{
String path = ServletActionContext.getServletContext().getRealPath("/images");
String filePath = path + "\\" + filename;
File file = new File(filePath);
return FileUtils.openInputStream(file);
//return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}