0

I using clojure+ring for build web application running on Glassfish 3. For correct initialization log4j i need find correct absolute path to WEB-INF folder.

Is the any way to determine absolute path to WEB-INF folder in web app running on app-server/

Amigo
  • 109
  • 7

1 Answers1

0

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:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • Thanks for response. But in clojure i'am using ring init function and i don't know, how i can access to ServletContext var. – Amigo Dec 08 '14 at 02:18