You can use the ServletContext.getRealPath() method.
For example, insert the following into an XHTML:
Path: #{request.servletContext.getRealPath("/")}
This will show the full path to your XHTML file, e.g. when you insert this into a file called index.xhtml
, it will show you the directory which contains this index.xhtml
.
Because most of the time, the XHTML files are not placed in the WEB-INF
folder, you may have to concat the strings in the following way:
#{request.servletContext.getRealPath("/")}WEB-INF
You can also do it in a handler:
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println("Path: " + request.getServletContext().getRealPath("/"));
See also: