jsp相对路径和绝对路径

1、
一、<base>标签的做用:
为页面上的全部连接规定默认地址或默认目标。
二、<base>标签的两个属性,target: 在何处打开页面中全部的连接; href: 规定页面中全部相对连接的基准 URL。
三、例子:
1)
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>">

jsp页面显示:
basePath:
http://localhost:8080/testProject/
2)
<% String realPath = application.getRealPath("/"); %>

jsp页面显示:
realPath:
D:\tomcat\webapps\testProject\
3)
${request.contextPath}
jsp页面显示:
contextPath:
/testProject
4)
若是请求是http://localhost:8080/testProject/page/test.jsp;

<%=request.getRequestURI() %>
jsp页面显示:
requestURI:
/testProject/page/test.jsp
2、
一、文件分隔符:unix系统:“/”,windows系统:“\”;
System.getProperty("file.separator")
二、路径分隔符:unix系统:“:”,windows系统:“;”;
System.getProperty("path.separator");
3、
1. <%=Thread.currentThread().getContextClassLoader().getResource("") %>
jsp页面显示:
file:/D:/tomcat/webapps/testProject/WEB-INF/classes/