上下文路径在可用的支持bean中
ExternalContext#getRequestContextPath()。
String contextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
因此,您可以例如:
String loginURI = contextPath + "/login.xhtml";// ...
注意,当用作JSF导航结果时,这是完全不必要的。有关正确的方法,请参见底部的第二个“另请参阅”链接。
上下文路径在EL
by中可用
HttpServletRequest#getContextPath()。
#{request.contextPath}因此,您可以例如:
<h:outputscript> // ... window.location = "#{request.contextPath}" + args.view;</h:outputscript>或当脚本位于
.js文件中时(正确的做法!):
<html lang="en" data-baseuri="#{request.contextPath}">window.location = document.documentElement.dataset.baseuri + args.view;


