想要下载链接上的弹出窗口...提示保存,打开,取消

JOH*_*HND 1 spring jsp file-upload spring-mvc

在我的jsp页面中,我提供了一个链接来查看/下载扫描的文档.

单击该链接后,我可以正确查看文档,但我希望jsp 在打开该文档之前提示打开,保存或取消选项.

我是否必须使用响应对象进行一些更改,或者是否因为浏览器设置而发生了变化.

谢谢.....!!!

我写了这样的控制器类:

public void fileUploadOption(HttpServletRequest request,HttpServletResponse response) {

        try {
              // get your file as InputStream
              InputStream is = new FileInputStream(new File(\\..file..\\));


              IOUtils.copy(is, response.getOutputStream());

              response.flushBuffer();

            } catch (IOException ex) {

              throw new RuntimeException("IOError writing file to output stream");
            }

    }
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 5

您需要将Content-Disposition标头设置为attachment.这将强制" 另存为"对话框.

在将任何字节写入响应主体之前添加此行:

String filename = file.getName();
response.setHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
Run Code Online (Sandbox Code Playgroud)

顺便说一句,在这种情况下,"上传"是错误的术语.我想这个方法来重命名fileSendOptionsendFile什么的.