在小脚本内写下如下代码
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.println(path);
out.println(request.getScheme());
out.println(request.getServerName());
out.println(request.getServerPort());
%>
<base href="<%=basePath%>">
<%
out.println(basePath);
%>
打印结果如下
/divisionScope http localhost 8080 http://localhost:8080/divisionScope/
得到如下结论:
request.getContextPath()---项目名
request.getScheme()--------协议名
request.getServerName()---服务器名
request.getServerPort()-----端口名
bathPath----------------------相当于转发
时间: 2024-10-13 16:07:05