struts文件下载时默认文件名出现乱码,该怎么解决?
下载功能能实现,但是默认文件名是中文时,出现下载窗口时文件名乱码。
下面是我写的代码,请大家帮我看一下应该怎么改
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws IOException {
FileService fileService = FileService.getInstance();
String fileID = request.getParameter("fileID");
String filePath = fileService.getFilePath(fileID);
String fileName = filePath.substring(filePath.lastIndexOf("/")+1); System.out.println(fileName);
response.setContentType("application/octet-stream;charset=ISO-8859-1");
response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");
ServletOutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(filePath);
byte[] b = new byte[8196];
int i = 0;
while ((i = in.read(b)) > 0) {
out.write(b, 0, i);
}
out.close();
in.close();
return null;
}