如何获得独立于服务器的固定基础url<%=request.getContextPath()%>&”;

how to get fixed base url independent of the server with the help of "<%=request.getContextPath()%>"

本文关键字:lt request getContextPath gt url 服务器 独立 何获得      更新时间:2023-09-26

我使用了var URL="<%=request.getContextPath()%>";以获取基本url。它在我的本地机器上运行良好。但它不在任何其他服务器中。请向我推荐的解决方案

javadocs:

servlet容器可能通过多个上下文路径与上下文匹配。在这种情况下,此方法将返回请求使用的实际上下文路径,并且它可能与ServletContext.getContextPath()方法返回的路径不同。ServletContext.getContextPath()返回的上下文路径应被视为应用程序的主要或首选上下文路径。

window.location.href = "${pageContext.request.contextPath}/welcome";