如何在Java项目配置根路径?

1、首先获取项目的根路径

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

2、在页面中配置根路径

<base href="<%=basePath%>">

3、使用配置好的根路径

在根路径后面加上要访问的路径即可

<a href="<%=basePath%>login">login</a>

例图:在这里插入图片描述

发布了20 篇原创文章 · 获赞 264 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/Mr_wxc/article/details/93235409