日期:2014-05-16  浏览次数:20342 次

弱弱的问一下,js如何获取当前项目的根路径?
    弱弱的问一下,js如何获取当前项目的根路径?就是类似于http://localhost:8080/,小菜求大神指教。还有啊,我在js中写了如下的代码
fm.action = '/prpall/processPolicyBatchPrint.do?actionType=queryPolicyDocumentType';
                fm.target='_parent';
                fm.submit();
这个submit之后还能再写一个类似的么,就是说我想让一个方法提交两次,就是action不同。

------解决方案--------------------
首先: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/

------解决方案--------------------
第二个问题是什么,不知道你具体想干什么,描述清晰一点
------解决方案--------------------
貌似有个 serverpath