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>
例图:![在这里插入图片描述](http://imgconvert.csdnimg.cn/aHR0cHM6Ly9pbWctYmxvZy5jc2RuaW1nLmNuLzIwMTkwNjIxMjE0MTQ2NjQucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2Uvd2F0ZXJtYXJrLHR5cGVfWm1GdVozcG9aVzVuYUdWcGRHayxzaGFkb3dfMTAsdGV4dF9hSFIwY0hNNkx5OWliRzluTG1OelpHNHVibVYwTDAxeVgzZDRZdz09LHNpemVfMTYsY29sb3JfRkZGRkZGLHRfNzA?x-oss-process=image/format,png)