JSP中相对路径问题 <base href="<%=basePath%>">
2016-10-08 11:06
459 查看
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>
首先这个是定位路径用的,表示该页面的请求是根路径下的,先看下request的方法,把上面的代码看懂,就容易理解了。
复习一下request 的常用方法:
request.getSchema()可以返回当前页面使用的协议,http 或是 https;
request.getServerName()可以返回当前页面所在的服务器的名字;
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80;
request.getContextPath()可以返回当前页面所在的应用的名字;
这样就不难理解这段代码的意思了。
http://127.0.0.1:8082/communication/login.jsp
这个地址就不难理解怎么回事了。
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>
首先这个是定位路径用的,表示该页面的请求是根路径下的,先看下request的方法,把上面的代码看懂,就容易理解了。
复习一下request 的常用方法:
request.getSchema()可以返回当前页面使用的协议,http 或是 https;
request.getServerName()可以返回当前页面所在的服务器的名字;
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80;
request.getContextPath()可以返回当前页面所在的应用的名字;
这样就不难理解这段代码的意思了。
http://127.0.0.1:8082/communication/login.jsp
这个地址就不难理解怎么回事了。
相关文章推荐
- (6)开发收获 <base href="<%=basePath%>">JSP页面中的相对路径问题
- JSP中<base href="<%=basePath%>">对相对路径的影响
- MyEclipse中建立的jsp文件中<base href="<%=basePath%>">可能会带来的问题.
- 很简单的JSP问题,<base href="<%=basePath%>">这句话什么意思?
- JSP中<base href="<%=basePath%>">作用
- 如何理解jsp页面中的“<base href="<%=basePath%>">”?
- 转载:如何理解jsp页面中的“<base href="<%=basePath%>">”?
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">的作用
- JSP中<base href="<%=basePath%>">作用
- JSP中的 < base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- 转载:如何理解jsp页面中的“<base href="<%=basePath%>">”?
- JSP中<base href="<%=basePath%>">作用
- JSP中 <%@ include file="相对url"%>和path basePath