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