在jsp中加上 % String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; % script $(function(){ var rootPath = "% = bathPath%" ; alert(rootPath); } /
在jsp中加上
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script>
$(function(){
var rootPath = "<%=bathPath%>";
alert(rootPath );
}
</script>