首页 > 其他 > 详细

index文件,使用相对路径和绝对路径

时间:2016-07-13 13:57:37      阅读:325      评论:0      收藏:0      [点我收藏+]

技术分享

加上/,表示服务器的根目录,

访问:http://localhost:8080/ServletPathDirection/index.jsp,进而跳转到http://localhost:8080/servlet/HelloServlet

 

不加/,

访问:http://localhost:8080/ServletPathDirection/index.jsp,进而跳转到http://localhost:8080/ServletPathDirection/servlet/HelloServlet

 

技术分享

 

<body>
<h1>Servlet路径跳转</h1>
<!-- 使用相对路径访问HelloServlet -->
  <!-- /servlet/HelloServlet 第一个/表示服务器的根目录 -->
  <a href="servlet/HelloServlet">访问HelloServlet</a><br>


  <!-- 使用绝对路径 访问HelloServlet,可以使用path变量:path变量表示项目的根目录 -->
  <a href="<%=path%>/servlet/HelloServlet">访问HelloServlet</a><br>

</body>

 

以上是通过超链接的方式访问servlet,通过表单的方式访问的写法同上(表单中action的URL地址写法,与超链接的方式完全相同)

 

 

注:web.xml 中url-pattern 处必须以 / 开头,这里的 / 表示项目的根目录

技术分享

 

在servlet当中路径跳转问题:

 

index文件,使用相对路径和绝对路径

原文:http://www.cnblogs.com/huiziz/p/5666551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!