场景:
把文件上传到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
}