web前端获取项目绝对路径

jsp获取项目绝对路径:

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"

%>

js文件中获取项目绝对路径:

var protocol = location.protocol; //获取http或https

var host = window.location.host; //获取IP和端口号

var contextPath = window.location.pathname.split("/")[1]; //获取项目名

var basePath = protocol +"//"+host+"/"+contextPath;

springboot前端页面获取项目绝对路径:

<script th:inline="javascript" type="text/javascript"> var ctx = [[@{/}]];</script>

发布了73 篇原创文章 · 获赞 44 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_34928194/article/details/103503903