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>
例图: