I am using Tomcat. I would like to put the config file in WEB-INF
instead of the default root class path which is WEB-INF/classes
. Currently I put
You can use getServletConfig() method return an instance of ServletConfig.
ServletContext sc=getServletConfig().getServletContext();
EDIT:
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
ServletContext sc=getServletContext();
...
}
The method getRealPath()
is not guaranteed to work, e.g. if your webapp is not expanded from a war file there is no 'real path' on the filesystem to a file inside the war file.
Since you say you are using a ServletContextListener, you can get the ServletContext out of the ServletContextEvent:
sce.getServletContext().getResourceAsStream("/WEB-INF/config.xml");