且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用JSF下载文件

更新时间:2023-12-04 17:45:10

可能是请求中的问题-它具有标头Faces-Request部分/ajax.但是我不确定.

这表明该请求是ajax请求.您无法通过ajax下载文件. Ajax请求由JavaScript处理,出于明显的安全原因,它没有以编程方式弹出另存为对话框或访问/操纵客户端磁盘文件系统的功能.

This suggests that the request is an ajax request. You can't download files by ajax. Ajax requests are processed by JavaScript which has for obvious security reasons no facilities to programmatically pop a Save As dialogue nor to access/manipulate client's disk file system.

您的代码段未显示您正在使用ajax.也许您过度简化了它,或者您正在使用ICEfaces,它可以在所有标准JSF命令组件上自动启用ajax.

Your code snippet does however not show that you're using ajax. Perhaps you oversimplified it too much or you're using ICEfaces which silently auto-enables ajax on all standard JSF command components.

无论如何,您都需要确保它发送ajax请求.

In any case, you need to make sure that it's not sending an ajax request.

  • How to provide a file download from a JSF backing bean?
  • ICEfaces libary in classpath prevents Save As dialog from popping up on file download