read url jsf 1

read url jsf

HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String url = req.getRequestURL().toString();
return url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath() + "/";
// ...

Here is what the above code is Doing:
1. Get the current request object.
2. Get the URL of the request.
3. Get the context path of the request.
4. Return the URL of the request, minus the request URI, plus the context path.

Similar Posts