×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Nhan Tran
Added: Aug 7, 2021 1:04 PM
Views: 3644
Tags: no tags
  1.   ServletContext context = sce.getServletContext();
  2.         String ffiles = context.getInitParameter("param");
  3.         InputStream is;
  4.         BufferedReader rd;
  5.         Map<String, String> sitemap = new HashMap<>();
  6.         try {
  7.             // initialize log4j here
  8.             String log4jConfigFile = context.getInitParameter("log4j-config-location");
  9.             String fullPath = context.getRealPath("") + File.separator + log4jConfigFile;
  10.             PropertyConfigurator.configure(fullPath);
  11.             // initialize log4j end
  12.             is = context.getResourceAsStream(ffiles);
  13.             rd = new BufferedReader(new InputStreamReader(is));
  14.             String records;
  15.             while ((records = rd.readLine()) != null) {
  16.                 String[] files = records.split(";");
  17.                 sitemap.put(files[0], files[1]);
  18.             }
  19.             context.setAttribute("SITEMAP", sitemap);
  20.  
  21.         } catch (IOException e) {
  22.             log.warn("ContextListener_IOException_Exception :  " + e.getMessage());
  23.         }