时间1024 2017-02-22 09:36 采纳率: 0%
浏览 2069

java web 项目开发中的文件上传与下载使用什么方式?

场景:
把文件上传到tomcat服务器的webapp中,把上传的文件url提供给其他应用或当前应用调用。
问题:
文件保存的路径应该在哪里?要建虚拟目录吗?表单提交后才上传到服务器?

我写的部分代码:
// 输出 : /项目名
String getContextPath = request.getSession().getServletContext().getContextPath();
// 去除/
String getContextName = request.getSession().getServletContext().getContextPath().substring(1,getContextPath.length());
System.out.println(realpath);
if(realpath2!=null){
int nIndex = realpath2.indexOf(getContextName);
realpath2 = realpath2.substring(0,nIndex)+"/Images";
System.out.println(realpath2);//D:\Program Files\apache-tomcat-7.0.55\webapps\/Images
}

  • 写回答

4条回答 默认 最新

  • threenewbee 2017-02-22 14:28
    关注

    保存路径是你的服务器决定的。上传下载可以用httpclient,另外用jsp写一个接收保存上传文件的程序,下载tomcat自带,只要这个目录配置为允许下载。

    评论

报告相同问题?