jsp中获取项目根路径:

  方法①

  最顶部增加代码:

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

  然后在head标签增加代码:

<base href="<%=basePath%>">

  结果为:http://localhost:8080/MyWeb/

  

  方法②

  只在head标签引入JSTL表达式

<base href="${pageContext.request.contextPath}">

  结果为:/MyWeb

 

idea下使用方法①有些情况下,例如maven下会报错,可以点此查看解决方法

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2021-11-10
  • 2021-09-25
  • 2021-06-26
  • 2021-07-10
  • 2021-11-27
  • 2021-11-27
猜你喜欢
  • 2021-05-17
  • 2021-12-22
  • 2022-02-21
  • 2021-04-01
  • 2022-12-23
  • 2021-05-17
  • 2021-07-01
相关资源
相似解决方案