java的Page页面中地址处理

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

1.request.getContentPath() :返回当前页面所在的项目名字(例:/novel)

2.request.getScheme() :返回当前页面使用的协议,例:http,或https

3.request.getServerName() :返回当前页面所在的服务器名字,例:本地是localhost

4.request.getServerPort():返回服务器的端口号:例:8080,80等

5.<base href="<%=basePath%>">:基链接,该页面的所有链接都会加上这个基链接

6.<c:set var="ctx" value="${pageContext.request.contextPath }" />获得页面的基路径,有了<bath href="<%basePath%>" >就不用这个了

原文地址:https://www.cnblogs.com/-scl/p/7244143.html