Servlet下载文件文件名问题

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FileDBO fileDBO = new FileDBO();
String fileID = request.getParameter("fileId");

    FileInfor file = fileDBO.getSingleFile(Integer.parseInt(fileID));
    InputStream in = new FileInputStream(new File(file.getFile_path()));
    System.out.println(file.getFile_name());

    response.setContentType("application/x-msdownload");
    response.setHeader("Content-Dispostion", "attachment;filename=" + file.getFile_name());
    response.setHeader("Content-Dispostion", "attachment;filename=abd.jpg")

    OutputStream out = response.getOutputStream();
    byte []buffer = new byte[1024];
    int len = 0;
    while((len = in.read(buffer)) != -1){
        out.write(buffer, 0, len);
    }

    in.close();
    out.close();
}

在用servlet进行下载文件处理的时候不能正常设置下载的文件名,在浏览器上下载的文件的文件名是servlet的类名或者是url-patten,无论response.setHeader怎么设置都不起作用
图片说明

你的文件名称的key写错了,是大写的,修正如下试试:

  response.setHeader("Content-Disposition", "attachment;fileName="+fileName);