通过request获取服务器相对路径及绝对路径

一.
String scheme = request.getScheme();//http
String serverName = request.getServerName();//localhost
int port = request.getServerPort();//8080
String context = request.getContextPath();// /demo(项目名称);
String path = scheme+"://"+serverName+":"+port+context+"/"  // http://localhost:8080/demo/
二.
获取上传文件保存服务器的路径
String filePath = request.getSession().getServletContext().getRealPath("uploadFiles/pictures");
C:Program Files (x86)apache-tomcat-7.0uploadFilespictures
原文地址:https://www.cnblogs.com/fujingtao5470/p/10448553.html