Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve the web app root path in JSF Managed Bean

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

like image 204
hari Avatar asked Apr 30 '12 01:04

hari


1 Answers

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("/");
like image 62
Paul Vargas Avatar answered Nov 06 '22 10:11

Paul Vargas