How do you point the way to the properties of the file in the web project?



  • In brief, the ContextListenner class implements ServletContextListener to induce methods from ConnectionManager class before initializing the context. ConnectionManager class is designed to create a pool of links for the database. To initialize the bullet, I want to use the files. To count the file as follows:

    public static String getValue(String key) {
        try (BufferedReader br = new BufferedReader(
                new FileReader(new File("D:/Java/Projects/Dictionary/properties/dictionaries.properties")))) {
            Properties p = new Properties();
            p.load(br);
            return p.getProperty(key);
        } catch (IOException e) {
            return null;
        }
    }
    

    To find the file, I'm pointing absolute URL, but I understand it's not right. The project is in the same folder, the eclipse program in another folder, but when I point out the relative address in the method, it's looking in the eclipse file, not in the project folder. What do we do?

    введите сюда описание изображения



  • Decided by the event ServletContextEvent:

    event.getServletContext().getRealPath("/WEB-INF/classes/dictionaries.properties");
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2