jfinal上传下载

1. 上传

<form id="form1" method="post" enctype="multipart/form-data" >

<input type="file" id="upload" name="upload" />

<input type = "submit" class = "button" value = "保存"  />

</form>
String path_tmp = "";

        String real_path = "";

        String fileName = "";

        String file_url = "";

        String uploadDir = File.separator + "upload" + File.separator + "contract" + File.separator;

        path_tmp = PathKit.getWebRootPath() + uploadDir;

        UploadFile uploadFile = getFile("upload", path_tmp);

        fileName = uploadFile.getFileName();

        real_path = uploadFile.getSaveDirectory();

        file_url = real_path + fileName;

2. 下载

<a href="<%=path%>/requestform/downMarContract?file_url=${list_request.get(0).FILE_URL }">下载</a>
public void downMarContract() throws Exception{

        String file_url = getPara("file_url");

        File file = new File(file_url);

        if(file.exists()) {

            renderFile(file);

        }

    }

 

你可能感兴趣的:(jFinal)