gpt4 book ai didi

java - Vaadin7 如何从服务器下载文件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:04:02 25 4
gpt4 key购买 nike

我有文件资源

FileResource curResource = new FileResource(new File(basepath +
"/WEB-INF/docs/"+path+".pdf"));

我想通过单击按钮从计算机上的浏览器保存此文件。我怎么能在 Vaadin 7 中做到这一点?谢谢

我尝试这样的事情:

ExternalResource resource = new ExternalResource(basepath +
"/WEB-INF/icons/"+"block_16.png");
Page.getCurrent().open(resource.getURL(),"Download",true);

但我的 about:blank 页面是空的,没有任何反应......

最佳答案

我解决了我的问题!

private String basepath = VaadinService.getCurrent()
.getBaseDirectory().getAbsolutePath();
private Button saveExcel = new Button();
Resource res = new FileResource(new File(basepath +
"/WEB-INF/docs/settings.xlsx"));
FileDownloader fd = new FileDownloader(res);
fd.extend(saveExcel);

在Vaadin中从服务器下载非常容易

关于java - Vaadin7 如何从服务器下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15762991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com