您的位置:首页 > 编程语言 > Java开发

java的Page页面中地址处理

2017-07-27 12:02 120 查看
<%
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%>" >就不用这个了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: