首先: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/

解决方案 »

  1.   

    第二个问题就是说我想在一个js方法中打开两个页面,这个过程我希望是走action的。
      

  2.   

    我在弱弱的问一句这个怎么在window.open()中传参数啊?
      

  3.   

     我在弱弱的问一句这个怎么在window.open()中传参数啊?直接在URL后面+可以么?  比如 window.open("www.baidu.com?type=1");   
      

  4.   

    我在弱弱的问一句这个怎么在window.open()中传参数啊?直接在URL后面+可以么?  比如 window.open("www.baidu.com?type=1");   可以直接在URL后加参数,不过中文容易乱码