jsp中获取页面的相对路径

1.在jsp页面的上方加上这段java代码

<%
//        request.getContextPath() 返回当前页面所在的应用的名字;
//        request.getSchema() 返回当前页面使用的协议,如:http;
//        request.getServerName() 返回当前页面所在的服务器的名字;
//        request.getServerPort() 返回当前页面所在的服务器使用的端口 String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %>

 2.在jsp页面的<head></head>下加上这段代码

<head>
    <base href="<%=basePath%>">
     <script src="js/jquery-1.9.1.js"></script>
</head> 

这样就可以了

原文地址:https://www.cnblogs.com/2016-10-07/p/7345555.html