通过request获取服务器相对路径及绝对路径
Posted 不忘初心|方得始终
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过request获取服务器相对路径及绝对路径相关的知识,希望对你有一定的参考价值。
一.
String scheme = request.getScheme();//http
String serverName = request.getServerName();//localhost
String 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
以上是关于通过request获取服务器相对路径及绝对路径的主要内容,如果未能解决你的问题,请参考以下文章
PyQt5 技巧篇-解决相对路径无法加载图片问题,styleSheet通过"相对"路径加载图片,python获取当前运行文件的绝对路径。