How do I get request url in jsf managed bean without the requested servlet?

前端 未结 4 1578
予麋鹿
予麋鹿 2020-12-07 22:35

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.

4条回答
  •  北海茫月
    2020-12-07 23:16

    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:

    
    

提交回复
热议问题