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