Assuming the URL is http://localhost:8080/project-name/resource.xhtml,
I want to obtain the following http://localhost:8080/project-name in a JSF managed bean.
The best way is to access to the ExternalContext RequestHeaderMap attributes.
ExternalContext ext = FacesContext.getCurrentInstance().getExternalContext();
Map requestHeader = ext.getRequestHeaderMap();
urlRefered = requestHeader.get("referer");
You could save the urlRefered attribute in your bean and process in your xhtml page as following: