Downloading a file from spring controllers

前端 未结 14 893
渐次进展
渐次进展 2020-11-22 01:06

I have a requirement where I need to download a PDF from the website. The PDF needs to be generated within the code, which I thought would be a combination of freemarker and

14条回答
  •  终归单人心
    2020-11-22 01:43

    What I can quickly think of is, generate the pdf and store it in webapp/downloads/< RANDOM-FILENAME>.pdf from the code and send a forward to this file using HttpServletRequest

    request.getRequestDispatcher("/downloads/.pdf").forward(request, response);
    

    or if you can configure your view resolver something like,

      
        
        
        
        
      
    

    then just return

    return "RANDOM-FILENAME";
    

提交回复
热议问题