wicket的上传和下载

上传:

Html页面:

<form wicket:id="uploadForm">

    <input type="file" wicket:id="fileUpload"/>

    <input type="submit" value="上传">

</form>

Page类:

        //创建文件上传控件FileUploadField
        final FileUploadField fileUpload = new FileUploadField("fileUpload");
        Form uploadForm = new Form("uploadForm"){
            @Override
            public void onSubmit(){
                FileUpload fu = fileUpload.getFileUpload();
                if(fu != null){
                    try {
                        fu.writeTo(new File("d:\\uu.txt"));
                    } catch (IOException ex) {
                         System.out.println("上传失败!");
                    }
                }
                super.onSubmit();
            }
        };
        uploadForm.add(fileUpload);
        uploadForm.setMultiPart(true);    //设置为true允许上传
        uploadForm.setMaxSize(Bytes.kilobytes(1000));    //设置上传最大值为1M

下载:

一般来说,如果是安全性不需要太高的时候,使用静态链接,用户直接访问该链接。

如果不想用户知道文件存放的目录,以增加安全性,可以使用wicket的DownloadLink控件实现动态链接

Html页面:

<a wicket:id="downloadLink">downloadLink</a>

Page类:

        ////////////////////使用downloadLink/////////////////
        File fileToDownload = new File("f:\\Winter.jpg");
        add(new DownloadLink("downloadLink",fileToDownload));

你可能感兴趣的:(html,F#,Gmail,wicket)