Java 下载excel生成的文件

Java 下载excel生成的文件,java,excel,spring-boot,Java,Excel,Spring Boot,我的html页面上有这个按钮。 当我单击它时,会触发EXCEL。 然后生成excel工作簿并保存到路径 我想要一个提示,告诉我你想把文件下载到哪个路径?或保存到浏览器的Deafolt“下载”文件夹位置 @GetMapping(value = "/coaExport", params = "action=excel") public void exportCOAExcel(HttpServletRequest request, HttpServletResponse response) throw

我的html页面上有这个按钮。 当我单击它时,会触发EXCEL。 然后生成excel工作簿并保存到路径

我想要一个提示,告诉我你想把文件下载到哪个路径?或保存到浏览器的Deafolt“下载”文件夹位置

@GetMapping(value = "/coaExport", params = "action=excel")
public void exportCOAExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    //loogic to fill up the excel workbook with data

    FileOutputStream outputStream = new 
    FileOutputStream("C:\\Users\\user\\Desktop\\revenue.xls");
    workbook.write(outputStream);
    outputStream.close();

}

您需要向浏览器发送内容处置响应,以便浏览器能够理解它是要下载的文件


我假设您的web应用程序正在服务器上运行—将文件保存到服务器上的特定位置没有意义—相反,您需要将文件发送到HttpServletResponse并设置正确的头。您无法选择文件保存的位置-这取决于用户的浏览器。您将如何将文件发送到响应?可能存在重复的