现在的位置: 首页 > 综合 > 正文

关于 2018年01月11日 ⁄ 综合 ⁄ 共 975字 ⁄ 字号 评论关闭

在未定义<base href="<%=basePath%>">之前:

<a href="/index.jsp">注册用户</a> :实际URL:http://localhost:8080/index.jsp  显然这是tomcat的初始页面,这显然不是我们想要的,相对于服务器的路径

<a href="index.jsp">注册用户</a> :实际URL:http://localhost:8080/day24/my/name/index.jsp   /my/name为当前页面路径  可以看出不加/即为相对当前页面下的路径

在定义<base href="<%=basePath%>">后:

<a href="/index.jsp">注册用户</a> :实际URL:http://localhost:8080/index.jsp  任然是相对于服务器的路径

<a href="index.jsp">注册用户</a> :实际URL:http://localhost:8080/day24/index.jsp   这才是我们想要的路径,相对于basePath的路径

总结:

1.加入<base href="<%=basePath%>是为<a href="index.jsp">起作用,这中写法为相对于base的相对路径。

2.“/”为虚拟路径,为服务器的路径。

3.当前环境的写法为: href="/day24/index.jsp"。

继续测试以下路径:

在未定义<base href="<%=basePath%>">之前:

"./":代表目前所在的目录。http://localhost:8080/day24/my/name/index.jsp

"../":代表上一层目录。http://localhost:8080/day24/my/index.jsp

在定义<base href="<%=basePath%>">后:

"./":代表目前所在的目录。http://localhost:8080/day24/index.jsp

"../":代表上一层目录。http://localhost:8080/index.jsp

重点:分清相对路径 与根路径,相对路径相对谁?!


href="index.jsp" href="./index.jsp" href="../index.jsp"均为相对路径,根据base的定义 相对的对象也有所不同

【上篇】
【下篇】

作者:

  • 该日志由 annoyance 于5年前发表在综合分类下,最后更新于 2018年01月11日.
  • 转载请注明: 关于 +复制链接

抱歉!评论已关闭.