Servlet:当前资源和目标资源之间的相对位置关系

第一种情况:

(1) 当前资源:location.html
http://localhost/Servlet_war_exploded/location.html
(2)目标资源:
http://localhost/Servlet_war_exploded/responseDemo2

相对路径可以写成:./responseDemo2
或者省略‘./’ 写成:responseDemo2
绝对路径可以写成:/Servlet_war_exploded/responseDemo2
浏览器之间访问需要加虚拟目录:/Servlet_war_exploded

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>相对和绝对路径</title>
</head>
<body>
<h1>相对路径</h1>
<h1>找到当前资源和目标资源之间的相对位置关系</h1>
<P>
    当前资源:location.html
    http://localhost/Servlet_war_exploded/location.html
</P>
<P>
    目标资源:
    http://localhost/Servlet_war_exploded/responseDemo2
</P>

<!--
    三个路径的写法都可以访问到/responseDemo2
    ./表示当前资源
-->
<a href="./responseDemo2">
    responseDemo2
</a>
<!--当是./时,可以省略./-->
<a href="responseDemo2">
    responseDemo2
</a>
<br>
<hr>
<h1>绝对路径</h1>
<a href="/Servlet_war_exploded/responseDemo2">
    responseDemo2
</a>
</body>
</html>

第二种情况:当前资源前面还有htmls文件夹,即同一父目录(虚拟目录)Servlet_war_exploded下,多了一级

(1)当前资源:location2.html
http://localhost/Servlet_war_exploded/htmls/location2.html
(2)目标资源:
http://localhost/Servlet_war_exploded/responseDemo2

相对路径可以写成: ‥/responseDemo2
绝对路径可以写成:/Servlet_war_exploded/responseDemo2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>找到当前资源和目标资源之间的相对位置关系</h1>
<P>
    当前资源:location2.html
    http://localhost/Servlet_war_exploded/htmls/location2.html
</P>
<P>
    目标资源:
    http://localhost/Servlet_war_exploded/responseDemo2

</P>
<!-- ../表示退回到上一级-->
<a href="../responseDemo2">
    responseDemo2
</a>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值