自由飞翔

我在仰望,java之上

统计

留言簿(2)

我关注的blog

阅读排行榜

评论排行榜

jsp相对路径和绝对路径

一、
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

posted on 2011-08-22 02:29 GavinMiao 阅读(5383) 评论(0)  编辑  收藏 所属分类: jsp


只有注册用户登录后才能发表评论。


网站导航: