JSP中的 < base href="<%=basePath%>">作用

来源:互联网 发布:redis 安装配置 linux 编辑:程序博客网 时间:2024/06/07 05:36

小记 JSP中的 < base href=”<%=basePath%>”>作用:

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

获取当前项目的路径,如:http://localhost:8080/项目名称。

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

这是设置当前界面的基础路径,默认表示表示该页面的请求是根路径下的。basePath上面中的变量,简单的静态网页的话你设置比如:<base href="http://localhost:8080//MYTest">,那你下面的href属性就会以你上面设的为基准,如:
<a href="http://localhost:8080//MYTest/xxx.htm"></a>
可以写成:<a href="xxx.htm"></a>

0 0