JFinal文件下载及设置路径

一:利用超链接

 <a href="/download/a.docx">download</a>

二:java代码

    1.页面

    <a href="/download">下载</a>

   2.路径

    public void configConstant(Constants me) {
me.setBaseUploadPath("upload");// 配置文件上传路径
me.setBaseDownloadPath("/download");//配置文件下载路径

      }

   3.代码

     public void download() {
String path = getSession().getServletContext().getRealPath("download");
File file = new File(path + "/a.docx");
System.out.println(path);
System.out.println(file.exists());
if (file.exists()) {
renderFile(file);
} else {
renderJson("文件不存在");
}
}

 4.结果

  

转自:http://blog.csdn.net/m0_37934074/article/details/78130412

原文地址:https://www.cnblogs.com/learningJAVA/p/8566553.html