I have a primefaces web application running on tomcat 8. In META-INF/context.xml
I defined the following:
The context path is in backing bean available by ExternalContext#getRequestContextPath().
String contextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
So you could do for example:
String loginURI = contextPath + "/login.xhtml";
// ...
Note that this is completely unnecessary when using as JSF navigation outcome. For the correct approach, see the second "See also" link in bottom.
The context path is available in EL by HttpServletRequest#getContextPath().
#{request.contextPath}
So you could do for example:
<h:outputScript>
// ...
window.location = "#{request.contextPath}" + args.view;
</h:outputScript>
Or when your script is in a .js
file (correct practice!):
<html lang="en" data-baseuri="#{request.contextPath}">
window.location = document.documentElement.dataset.baseuri + args.view;