一:利用超鏈接
<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
