国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

servlet獲取并存儲web.xml中context-param參數

2019-11-14 22:36:51
字體:
來源:轉載
供稿:網友
servlet獲取并存儲web.xml中context-param參數

在web.xml中定義了context-param,一般不會隨意改動,所以在監聽器中做一次處理,容器啟動時讀取并存儲在PRoperties中,方便以后取值。

SysProperties 類用于存儲 context 鍵值;

SystemListener 監聽器類,處理 context-param 參數。

/** * 用于存儲參數鍵值 */public final class SysProperties {    private static SysProperties instance;    private Properties initProperties = new Properties();    private SysProperties() { }    public static SysProperties getInstance() {        if (instance == null) {            instance = new SysProperties();        }        return instance;    }    /**     * 獲取對應的值     * @param key String 提供的鍵(param-name)     * @return String 鍵對應的值(param-value)     */    public String getProperty(String key)    {        return this.initProperties.getProperty(key);    }    /**     * 檢測是否包含該鍵     * @param key String 鍵     * @return boolean 該鍵存在返回 true,否則返回 false     */    public boolean containsKey(String key) {        return this.initProperties.containsKey(key);    }    /**     * 存儲參數     * @param key String param-name     * @param object String param-value     */    public void put(String key, String object) {        this.initProperties.put(key, object);    }}

/** * 系統監聽,程序啟動時初始化并存儲相關參數 */public class SystemListener implements ServletContextListener {    @Override    public void contextInitialized(ServletContextEvent servletContextEvent) {        initContextParam(servletContextEvent);    }    @Override    public void contextDestroyed(ServletContextEvent servletContextEvent) { }    private void initContextParam(ServletContextEvent event) {        Enumeration<String> names = event.getServletContext().getInitParameterNames();        while (names.hasMoreElements())        {            String name = names.nextElement();            String value = event.getServletContext().getInitParameter(name);            SysProperties.getInstance().put(name, value);        }    }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麻栗坡县| 乐安县| 安陆市| 灵川县| 年辖:市辖区| 拉孜县| 沽源县| 万源市| 故城县| 密云县| 石家庄市| 宜兴市| 锡林郭勒盟| 江陵县| 买车| 绥滨县| 盖州市| 霍城县| 蚌埠市| 浮山县| 青阳县| 洪雅县| 井陉县| 日照市| 汤原县| 万源市| 思南县| 永平县| 苗栗县| 腾冲县| 铜梁县| 若尔盖县| 聊城市| 图们市| 扬州市| 视频| 新巴尔虎左旗| 左贡县| 鄄城县| 宿州市| 沙湾县|