一旦我将库icefaces.jaricepush.jaricefaces_ace.jar添加到我的类路径中以便使用ACE组件,我的另存为对话框就不会弹出吗?我不确定这是否是一个错误,但如果类路径中没有库,它就可以工作。这是我的另存为方法:
public void downloadFile(String propertyPath) throws IOException {
ProxyFile fileToDownload = repBean.downloadFile(propertyPath);
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
response.reset(); response.setContentType(fileToDownload.getContentType());
response.setHeader("Content-Length", String.valueOf(fileToDownload.getLength()));
response.setHeader("Content-disposition", "attachment; filename=\"" + fileToDownload.getName() + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
input = new BufferedInputStream(fileToDownload.getContent());
output = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[10240];
for (int length; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
} finally {
output.close();
input.close();
facesContext.responseComplete();
}
}
您无法使用ajax 下载文件。
Ajax 是由 JavaScript 执行的XMLHttpRequest
目的。请求将成功执行,并且响应将成功检索。但是,JavaScript 无法将响应写入客户端的磁盘文件系统,也无法强制执行Save As与给定响应的对话。这将是一个巨大的安全漏洞。
你的具体问题的原因是 ICEfaces 本身。也就是说,当您将 ICEfaces 集成到 JSF Web 应用程序中时,所有标准<h:commandXxx>
链接/按钮将默默地变成支持 ajax 的链接/按钮,这确实会导致初学者感到困惑。确保下载链接/按钮没有隐式使用 ICEfaces 引入的 ajax 工具。根据他们的有关该主题的 wiki 页面 http://www.icesoft.org/wiki/display/ICE/Disabling+Ajax,你需要显式嵌套一个<f:ajax disabled="true">
禁用此功能。
禁用组件的 Ajax
您还可以在单个组件级别禁用 Ajax:
<h:commandButton value="Send" actionListener="#{bean.sendMessage}">
<f:ajax disabled="true"/>
</h:commandButton>
将其应用到您的下载链接/按钮上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)