System.out.println("getContextPath:"+req.getContextPath());
System.out.println("getServletPath:"+req.getServletPath());
System.out.println("getRequestURI:"+req.getRequestURI());
System.out.println("getRequestURL:"+req.getRequestURL());
System.out.println("getRealPath:"+req.getSession().getServletContext().getRealPath("image") );
输出结果为
getContextPath:/maven
getServletPath:/upload.do
getRequestURI:/maven/upload.do
getRequestURL:http://localhost:8080/maven/upload.do
getRealPath:D:\myecllipse\apache-tomcat-7.0.77-windows-x64\apache-tomcat-7.0.77\wtpwebapps\hcwproject\image
最后一个路径其实是工程在那个目录运行路径,不该路径默认会在工作空间
原文地址:https://www.cnblogs.com/itzyz/p/12262266.html
时间: 2024-10-09 07:55:06