一、
1、<base>标签的作用: 为页面上的所有链接规定默认地址或默认目标。
2、<base>标签的两个属性,target: 在何处打开页面中所有的链接; href: 规定页面中所有相对链接的基准 URL。
3、例子:
1)
<%
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)
jsp页面显示:
basePath:
http://localhost:8080/testProject/
2)
<% String realPath = application.getRealPath("/"); %>
jsp页面显示:
realPath:
realPath:
D:\tomcat\webapps\testProject\
3)
3)
${request.contextPath}
4)
如果请求是http://localhost:8080/testProject/page/test.jsp;
1、文件分隔符:unix系统:“/”,windows系统:“\”;
jsp页面显示:
contextPath:
/testProject
contextPath:
4)
如果请求是http://localhost:8080/testProject/page/test.jsp;
<%=request.getRequestURI() %>
二、
jsp页面显示:
requestURI:
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/