在jsp页面顶上面定义

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

然后JavaScript里面获取

<script type="text/javascript">
var baseUrl="<%=basePath%>";
</script>

获取的url例如:

request.getScheme() = "http"
request.getServerName() = "localhost"
request.getServerPort() = "8080"
request.getContextPath() = "wms-web-enterprise"
baseUrl = "http://localhost:8080/wms-web-enterprise/"

05-13 16:59
查看更多