通常在界面中的资源文件比如js,图片,css等通过绝对路径和相对路径访问时,在你的机器或者在你部署的生产环境当时程序是没问题的但是当你换服务器很可能出问题,导致找不到文件,所以一般使用java直接得到服务路径代码如下,直接增加到jsp界面的头部
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basepath",basepath);
%>
使用方式
<link rel="stylesheet" type="text/css" href="./css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="${basepath}css/bootstrap-theme.css"/>
<link rel="stylesheet" type="text/css" href="${basepath}widget/zTree/css/zTreeStyle/zTreeStyle.css"/>
效果
<link rel="stylesheet" type="text/css" href="./css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/lab/css/bootstrap-theme.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/lab/widget/zTree/css/zTreeStyle/zTreeStyle.css"/>