以下是controller
@RequestMapping("/download")
public void download(@RequestParam("filePath") String path2, HttpServletResponse response) {
String path = servletContext.getRealPath("/");
File file = new File(path2);
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName="+file.getName());
ServletOutputStream out;
file = new File(path + "File/" + file.getName());
try {
FileReader fr = new FileReader(file);
BufferedReader reader = new BufferedReader(fr);
String str = reader.readLine();
while (str != null) {
//String fileName = new String(str.getBytes("GBK"),"utf-8");
System.out.println(str);
str = reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
FileInputStream inputStream = new FileInputStream(file);
out = response.getOutputStream();
byte[] buffer = new byte[8192];
while (inputStream.read(buffer)!=-1){
out.write(buffer);
out.flush();
}
inputStream.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
页面的响应头

页面的响应内容
