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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM