2014-12-05 16 views
0

我使用clojure + ring来构建在Glassfish 3上运行的Web应用程序。 对于正确的初始化log4j,我需要找到WEB-INF文件夹的正确绝对路径。查找应用程序文件夹clojure/ring的正确答案路径

的是任何方式来确定web应用程序的WEB-INF文件夹的绝对路径应用程序服务器上运行/

回答

0

可以使用ServletContext.getRealPath()方法。

例如,插入以下为XHTML:

Path: #{request.servletContext.getRealPath("/")} 

这将显示完整路径XHTML文件,例如当您将其插入名为index.xhtml的文件时,它会显示包含此文件的目录index.xhtml

因为大部分的时候,XHTML文件不放置在WEB-INF文件夹,您可能必须Concat的字符串以下列方式:

#{request.servletContext.getRealPath("/")}WEB-INF 

你也可以做一个处理程序:

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest(); 

    System.out.println("Path: " + request.getServletContext().getRealPath("/")); 

参见:

+0

感谢响应。但在clojure我使用ring init函数,我不知道,我怎么可以访问ServletContext var。 – Amigo 2014-12-08 02:18:43

相关问题