admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/PropertyUtil.java
@@ -1,42 +1,42 @@
package com.yeshi.fanli.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
public class PropertyUtil {
   public static Properties getPropertys(String fileName) {
      ClassLoader classLoader = PropertyUtil.class.getClass().getClassLoader();
      Properties pe = new Properties();
      try {
         pe.load(classLoader.getResourceAsStream(fileName));
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return pe;
   }
   // 获取属性
   public static Properties getPropertys(HttpServletRequest request, String fileName) {
      try {
         if (request.getSession().getServletContext().getAttribute(StringUtil.getBase64String(fileName)) != null)
            return (Properties) request.getSession().getServletContext()
                  .getAttribute(StringUtil.getBase64String(fileName));
         Properties pe = getPropertys(fileName);
         request.getSession().getServletContext().setAttribute(StringUtil.getBase64String(fileName), pe);
         return pe;
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }
}
package com.yeshi.fanli.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
public class PropertyUtil {
   public static Properties getPropertys(String fileName) {
      ClassLoader classLoader = PropertyUtil.class.getClass().getClassLoader();
      Properties pe = new Properties();
      try {
         pe.load(classLoader.getResourceAsStream(fileName));
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return pe;
   }
   // 获取属性
   public static Properties getPropertys(HttpServletRequest request, String fileName) {
      try {
         if (request.getSession().getServletContext().getAttribute(StringUtil.getBase64String(fileName)) != null)
            return (Properties) request.getSession().getServletContext()
                  .getAttribute(StringUtil.getBase64String(fileName));
         Properties pe = getPropertys(fileName);
         request.getSession().getServletContext().setAttribute(StringUtil.getBase64String(fileName), pe);
         return pe;
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }
}