我正在尝试使用带有http:// ***** / download的DownloadServlet类下载xlsx文件?file_id = 1&file_type = xlsx 但该文件在chrome中以.zip文件下载 没有扩展名的Firefox
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String file_id = request.getParameter("file_id");
String filetype = request.getParameter("file_type");
String fileName = UserDao.getFile(file_id);
if (filetype == "xlsx") {
filetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
response.setContentType(filetype);
logger.debug(filetype);
// Make sure to show the download dialog
response.setHeader("Content-disposition",
String.format("attachment; filename=\"%s\"", Excelwriter.FNWOPath));
File my_file = new File(fileName);
OutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(my_file);
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0){
out.write(buffer, 0, length);
}
in.close();
out.flush();
}
答案 0 :(得分:0)
我只是忘记将Excelwriter.FNWOPath更改为fileName