【汇智学堂】-JSP中base href的作用

获取当前项目的路径,如:http://localhost:8080/项目名称/。
设置基础路径的,basePath为变量,简单的静态网页的话你设置比如:

<base href="http://www.jingyingjidi.com">

那你下面的href属性就会以你上面设的为基准,如:

<a href="http://www.jingyingjidi.com/xxx.htm"></a>

你现在就只需要写

<a href="xxx.htm"></a>

应用场景示例:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath%>">
	<meta charset="UTF-8">
	<title>网站内容管理</title>
	......
``<base href="value">为页面上所有相对 URL 规定基准 URL:

猜你喜欢

转载自blog.csdn.net/weixin_39593940/article/details/90904999
今日推荐