">

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:simsun; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:auto; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

base 标记是一个基链接标记,是一个单标记。用以改变文件中所有连结标记的参数内定值。它只能应用于标记 <head> </head> 之间。
你网页上的所有相对路径在链接时都将在前面加上基链接指向的地址。

 

base 元素可规定页面中所有链接的基准 URL
我们可以使用 <base> 标签中的 href 属性来设置,所有的 相对基准 URL”

 

这是 JSP 端的代码
采用了 html 文件中的 <base> 标签:
代码如下 :
<%
String path = request.getContextPath();
//
获得项目完全路径(假设你的项目叫 myWork ,那么获得到的地址就是 http://localhost:8080/myWork/ :
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

// " 项目路径 basePath" 放入 pageContext

%>
<html>
<head>
<base href=" <%=basePath%>">

//base 只能应用于标记 <head> </head> 之间
</head>
//
这里我们就可以直接使用相对路径 ( : 相对于 base 标签 )
<a href="jsp/login.jsp">Login </a>
</html>
当我们去执行上面的那段 JSP 代码后,我们可以在浏览器中可以查看,他所返回给客户端的 html 代码 :
执行完上述 JSP 后,所返回的 html 代码如下 :
<html>
<head>
<base href="http://localhost:8080/myWork/ ">
</head>
//
设置了 <base> 后,相对路径,相对于的就是 base 中的路径,而不再是浏览器地址的请求路径啦 ~~~
<a href="jsp/login.jsp">Login </a>
</html>

我们可以看到 JSP 返回的 html 代码中,包含了 <base href="http://localhost:8080/myWork/ "> 内容。
也就是说,在本 html 文件中,遇到的所有 相对链接 ( 例如 : <a href="jsp/login.jsp">)” ,都是相对于 base
的路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值