1.在当前JSP中的java代码中获取,再在JS中获取

在java项目中获取项目根路径的方法

2.在跳入当前页面的action中获取根路径,放入request中,再在JS中获取 

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

        + request.getServerName() + ":" + request.getServerPort()

        + path + "/";

request.setAttribute("basePath", basePath);

再在JS中通过EL表达式调用:

var basePath = ${'basePath'};

新手成长,如有不对,欢迎各位指教

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2021-07-14
  • 2021-11-18
  • 2021-11-27
  • 2021-07-17
  • 2021-09-11
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2021-11-18
  • 2021-05-17
  • 2021-11-29
  • 2021-12-28
  • 2021-11-18
相关资源
相似解决方案