通过 wicket 下载 zip 文件 [英] Download a zip file through wicket

查看:35
本文介绍了通过 wicket 下载 zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wicket 框架,并且我已经通过 Java 代码制作了一个 zip 文件,我想要一个链接来下载它,我不知道是否可能或者我应该通过 wicket 制作 zip 文件(但是不是 Java),然后有一个下载链接.

I am using wicket framework, and I have made a zip file by Java code, I want to have a link to download it, I don't know if it is possible or I should make the zip file by wicket (but not Java) and then have a link to download.

推荐答案

看一看 ZipResourceStream.使用此类,您可以动态生成目录的 zip 内容,并使用 org.apache.wicket.markup.html.link.ResourceLinkResourceStreamResource 链接到它.

Take a look at ZipResourceStream. With this class you can generate zip contents of a directory on the fly, and use a org.apache.wicket.markup.html.link.ResourceLink with ResourceStreamResource to link to it.

File file = new File(path);
IResourceStream resStream = new ZipResourceStream(file);
ResourceStreamResource resource = new ResourceStreamResource(resStream);
ResourceLink link = new ResourceLink("link", resource);
add(link);

或者,如果您更喜欢使用其他工具压缩文件,您可以使用 DownloadLink:

Alternatively, if you prefer to zip the file with another tool, you can use DownloadLink:

File zipFile = generateZipFile();
IModel fileModel = new Model(zipFile);
add(new DownloadLink("dllink", fileModel);

如果您更喜欢在链接的 onClick 中即时生成文件,请查看以下问题:如何使用 Wicket 的下载链接使用动态生成的文件?

If you prefer to generate the File on the fly in the Link's onClick, take a look at this question: How to use Wicket's DownloadLink with a file generated on the fly?

这篇关于通过 wicket 下载 zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆