通过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.0\uploadFiles\pictures

 

posted @ 2019-02-28 10:07  不忘初心5470  阅读(2581)  评论(0编辑  收藏  举报