I have a conf.properties in racine of webApplication and i have a method init in a class manageBDD to initialise parameters.
i call the method init in a servlet but the file is not reconised, when i call the method in the method main of class ManageBDD the method work.
Why in servlet the file is not reconised and in method main of class ManageBdd the file is reconised ?
(throws Exception is just for test the method...)
public static void init() throws Exception {
FileInputStream file = new FileInputStream("conf.properties");
Properties prop = new Properties();
prop.load(file);
pDriver = prop.getProperty("jdbc.driver");
pUrl = prop.getProperty("jdbc.url");
pLogin = prop.getProperty("jdbc.login");
pPass = prop.getProperty("jdbc.pass");
System.out.println("in class : " + prop.getProperty("jdbc.login"));
System.out.println("in class : " + prop.getProperty("jdbc.pass"));
System.out.println("in class : " + prop.getProperty("jdbc.driver"));
System.out.println("in class : " + prop.getProperty("jdbc.url"));
}
in main ManageBDD, method work :
public static void main(String[] args) throws Exception {
init();
}
in servlet doesn't work when i run the server :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
ManageBDD.init();
} catch (Exception e) {
e.printStackTrace();
}
//request.getRequestDispatcher("/index.jsp").forward(request, response);
}