首先:JS中是不能获取项目根路径的两种方法在JS中使用项目根路径:一、在当前JSP中的java代码中获取String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
再在JS中调用:var basePath = '<%=basePath%>';
alert(basePath); //http://localhost:8080/
二、在跳入当前页面的action中获取根路径,放入request中,再在JS中获取在action中存入request:String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
request.setAttribute("basePath", basePath);
再在JS中通过EL表达式调用:var basePath = ${'basePath'};
alert(basePath); //http://localhost:8080/
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
再在JS中调用:var basePath = '<%=basePath%>';
alert(basePath); //http://localhost:8080/
二、在跳入当前页面的action中获取根路径,放入request中,再在JS中获取在action中存入request:String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
request.setAttribute("basePath", basePath);
再在JS中通过EL表达式调用:var basePath = ${'basePath'};
alert(basePath); //http://localhost:8080/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货