码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-13 13:59:43      阅读:256      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!