Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Wicket:在提交后下载文件_Java_Web_Wicket_Wicket 1.5 - Fatal编程技术网

Java Wicket:在提交后下载文件

Java Wicket:在提交后下载文件,java,web,wicket,wicket-1.5,Java,Web,Wicket,Wicket 1.5,所以我有一个DataView,有三列,其中一列是checkbox列,允许用户检查他们想要下载的文件 为了简单起见(我认为);我决定将这些文件压缩成一个zip文件,并在生成后提供服务 以下是我目前掌握的情况: 代码:: 我得到了HTTP错误404:notfound你可以像DownloadLink那样从压缩文件创建FileResourceStream。然后,只需更改当前请求周期的目标: Button downloadLogButton = new Button("downloadlogbutton

所以我有一个
DataView
,有三列,其中一列是checkbox列,允许用户检查他们想要下载的文件

为了简单起见(我认为);我决定将这些文件压缩成一个zip文件,并在生成后提供服务

以下是我目前掌握的情况:

代码:



我得到了
HTTP错误404:notfound

你可以像
DownloadLink
那样从压缩文件创建
FileResourceStream
。然后,只需更改当前请求周期的目标:

Button downloadLogButton = new Button("downloadlogbutton") {
    private static final long serialVersionUID = 1L;
    @Override
    public void onSubmit() {
        // Some utility class I made that zips files
        LogUtility util = new LogUtility();
        util.zipLogFiles("sample", logs);
        IResourceStream resourceStream = new FileResourceStream(
            new org.apache.wicket.util.file.File(someFile)); // Use whatever file you need here
        IRequestTarget t = new ResourceStreamRequestTarget(stream){
            @Override
            public String getFileName() {
                return "filename.zip";
            }
        }
        getRequestCycle().setRequestTarget(t);
    }
};
如果您想在下载后删除该文件,可以覆盖
IRequestTarget\respond(RequestCycle)
,如下所示:

@Override
public void respond(RequestCycle requestCycle) {
    super.respond(requestCycle);
    // Delete the file
    ((FileResourceStream)getResourceStream()).getFile().delete();
}

以下相关问题也可能有用:.

因为我使用的是Wicket 1.5,所以我是这样做的:
org.apache.Wicket.util.file.log=new org.apache.Wicket.util.file.file(“/home/keeboi/Downloads/sample.zip”);IResourceStream resourceStream=新文件资源流(日志);IRequestHandler目标=新的ResourceStreamRequestHandler(resourceStream);getRequestCycle().scheduleRequestHandlerAfterCurrent(目标)但是我得到了
HTTP错误404:notfound
好的,这是我的实用程序类中的一个错误。谢谢
Button downloadLogButton = new Button("downloadlogbutton") {
    private static final long serialVersionUID = 1L;
    @Override
    public void onSubmit() {
        // Some utility class I made that zips files
        LogUtility util = new LogUtility();
        util.zipLogFiles("sample", logs);
        IResourceStream resourceStream = new FileResourceStream(
            new org.apache.wicket.util.file.File(someFile)); // Use whatever file you need here
        IRequestTarget t = new ResourceStreamRequestTarget(stream){
            @Override
            public String getFileName() {
                return "filename.zip";
            }
        }
        getRequestCycle().setRequestTarget(t);
    }
};
@Override
public void respond(RequestCycle requestCycle) {
    super.respond(requestCycle);
    // Delete the file
    ((FileResourceStream)getResourceStream()).getFile().delete();
}