一、
1、<base>標簽的作用:為頁面上的所有鏈接規定默認地址或默認目標。
2、<base>標簽的兩個屬性,target:在何處打開頁面中所有的鏈接;href:規定頁面中所有相對鏈接的基準 URL。
3、例子:
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
二、
1、文件分隔符:unix系統:“/”,windows系統:“\”;
System.getProperty("file.separator")
2、路徑分隔符:unix系統:“:”,windows系統:“;”;
System.getProperty("path.separator");
三、
1. <%=Thread.currentThread().getContextClassLoader().getResource("") %>
jsp頁面顯示:
file:/D:/tomcat/webapps/testProject/WEB-INF/classes/
Gavin