首页 > Web开发 > 详细

jsp中相对路径和绝对路径书写以及JSP中base标签使用

时间:2019-11-21 22:28:49      阅读:107      评论:0      收藏:0      [点我收藏+]

相对路径即从所在目录开始检索的路径

 ../   表示当前目录上一级

1 <body>
2     <a href="../LoginServlet">相对路径</a>
3 </body>

绝对路径即从根开始检索的路径

当然还有使用base标记

base标记是一个基链接标记,是一个单标记。用以改变文件中所有连结标记的参数内定值。它只能应用于标记<head>与</head>之间。

 1 <head>
 2 <%
 3     //http://localhost:8080/myweb/
 4     String contextPath = request.getContextPath();// /myweb
 5     String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
 6                       + contextPath + "/";
 7     //完整路径   basePath =  request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
 8    // +  request.getContextPath()  + "/" ;
 9 %>
10 <base href="<%= basePath%>">
11 </head>
12 <body>
13     <a href="LoginServlet">绝对路径</a>
14 </body>

 

jsp中相对路径和绝对路径书写以及JSP中base标签使用

原文:https://www.cnblogs.com/xieshilin/p/11908718.html

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