import javax.faces.context.FacesContext;
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
FacesContext facesCtx = FacesContext.getCurrentInstance();
ExternalContext ectx = facesCtx.getExternalContext();
HttpServletRequest req = (HttpServletRequest) ectx.getRequest();
String url = req.getRequestURL().toString();
return url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath();
sample output
http://localhost:7501/EmployeeAppDemo-ViewController-context-root
import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpServletRequest;
FacesContext facesCtx = FacesContext.getCurrentInstance();
ExternalContext ectx = facesCtx.getExternalContext();
HttpServletRequest req = (HttpServletRequest) ectx.getRequest();
String url = req.getRequestURL().toString();
return url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath();
sample output
http://localhost:7501/EmployeeAppDemo-ViewController-context-root
No comments:
Post a Comment