小tips:tomcat下JSP页面引用css、js等资源路径无法加载问题

时间:2021-03-10 13:06:37   收藏:0   阅读:0

在JSP页面头部添加如下代码:

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

在引用资源前面添加如下代码:

<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css" href="./resource/base.css">
<link rel="stylesheet" type="text/css" href="./resource/common.css">

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!