Retrieve the web app root path in JSF Managed Bean

hari picture hari · Apr 30, 2012 · Viewed 37.4k times · Source

Im trying to access the example/web folder (see below in the image) in a jsf managed bean but cant seem to find a way to do it

Im trying to access the **example/web** folder (see below in the image) in a jsf managed bean but cant seem to find a way to do it

thx

Answer

Paul Vargas picture Paul Vargas · Apr 30, 2012

Try

FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()

for build relative url's to resources in your app.

If you want the real path...

ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance()
            .getExternalContext().getContext();
String realPath = ctx.getRealPath("/");