JSP中获取项目部署的访问地址

request.getScheme()://返回当前链接使用的协议;一般应用返回http;SSL返回https;

request.getServerName()://可以返回当前页面所在的服务器的名字

request.getServerPort()://可以返回当前页面所在的服务器使用的端口,就是80,

request.getContextPath()://可以返回当前页面所在的项目的名称名字

<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

使用<%=basePath%>加你存放静态文件的位置,如:/static/upload/file/0cad201dd91d49fda68cbe6eccf24984.png

原文地址:https://www.cnblogs.com/foreverstudy/p/11661326.html