Servlet路径跳转1---使用相对路径和绝对路径,在页面上调用servlet的路径写法(超链接的方式和表单的方式)

课程1-13   http://www.imooc.com/video/5554

Servlet路径跳转:

  绝对路径:放在任何地方都对的路径

  相对路径:相对于当前资源的路径 

 

index文件

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

访问: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 处必须以 / 开头,这里的 / 表示项目的根目录

 

posted @ 2016-07-13 13:04  糖葫芦有点甜  阅读(936)  评论(0编辑  收藏  举报