弱弱的问一下,js如何获取当前项目的根路径?

又丑又萌的八戒 2014-01-06 10:16:51
弱弱的问一下,js如何获取当前项目的根路径?就是类似于http://localhost:8080/,小菜求大神指教。还有啊,我在js中写了如下的代码
fm.action = '/prpall/processPolicyBatchPrint.do?actionType=queryPolicyDocumentType';
fm.target='_parent';
fm.submit();
这个submit之后还能再写一个类似的么,就是说我想让一个方法提交两次,就是action不同。
...全文
15089 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 5 楼 ShenShiampMoYi 的回复:
貌似有个 serverpath
我在弱弱的问一句这个怎么在window.open()中传参数啊?
  • 打赏
  • 举报
回复
貌似有个 serverpath
  • 打赏
  • 举报
回复
引用 3 楼 YE809490404 的回复:
第二个问题是什么,不知道你具体想干什么,描述清晰一点
第二个问题就是说我想在一个js方法中打开两个页面,这个过程我希望是走action的。
栖凤之梧 2014-01-06
  • 打赏
  • 举报
回复
第二个问题是什么,不知道你具体想干什么,描述清晰一点
  • 打赏
  • 举报
回复
引用 1 楼 YE809490404 的回复:
首先: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/
那个第二个问题你会不,顺道帮忙解决一下呗。
栖凤之梧 2014-01-06
  • 打赏
  • 举报
回复
首先: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/
栖凤之梧 2014-01-06
  • 打赏
  • 举报
回复
引用 7 楼 ShenShiampMoYi 的回复:
[quote=引用 6 楼 PigRunO 的回复:] [quote=引用 5 楼 ShenShiampMoYi 的回复:] 貌似有个 serverpath
我在弱弱的问一句这个怎么在window.open()中传参数啊?[/quote]直接在URL后面+可以么? 比如 window.open("www.baidu.com?type=1"); [/quote] 可以直接在URL后加参数,不过中文容易乱码
  • 打赏
  • 举报
回复
引用 6 楼 PigRunO 的回复:
[quote=引用 5 楼 ShenShiampMoYi 的回复:] 貌似有个 serverpath
我在弱弱的问一句这个怎么在window.open()中传参数啊?[/quote]直接在URL后面+可以么? 比如 window.open("www.baidu.com?type=1");

87,919

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧