<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 作用 獲取全局初始化參數,共享資源,獲取資源文件. ## 生命周期 * 創建:服務器啟動的時候會為每個項目創建一個servletContext上下文對象,servletContext是項目的一個引用. * 銷毀:在服務器關閉或者移除項目的時候servletConext銷毀. ## 獲取 1. getservletConfig().getServletConext(). 2. getServletConext(). ## 常用方法 1. String getInitParameter(String name) 獲取指定的項目初始化參數 . 2. Enumeration getInitParameterNames() 獲取項目所有初始化參數名稱. 3. String getRealPath(string filepath) 獲取一個資源在服務器上的絕對路徑,從根目錄下讀取,以"/開始". 4. InputStream getResourceAsStream(String filepath) 以流的方式返回一個文件. 5. String getMimeType(String 文件名) 獲取一個文件的mime類型(text/html,image/gif) ## web.xml配置 ~~~ <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <context-param> <param-name>name</param-name> <param-value>jack</param-value> </context-param> <context-param> <param-name>age</param-name> <param-value>20</param-value> </context-param> </web-app> ~~~ ## 實例 ~~~ //獲取servletContext對象 ServletContext servletContext = getServletContext(); //獲取全局初始化參數 String name = servletContext.getInitParameter("name"); String age = servletContext.getInitParameter("age"); System.out.println(name); System.out.println(age); //獲取所有全局初始化參數名稱 Enumeration<String> initParameterNames = servletContext.getInitParameterNames(); while (initParameterNames.hasMoreElements()) { String n = (String) initParameterNames.nextElement(); System.out.println(n); System.out.println(servletContext.getInitParameter(n)); } //獲取一個資源在服務器上的真實路徑 String realPath = servletContext.getRealPath("/1.html"); System.out.println(realPath); //以流的形式返回一個文件 InputStream resourceAsStream = servletContext.getResourceAsStream("/1.html"); System.out.println(resourceAsStream); //獲取一個文件的mime類型(大類型/小類型) String mimeType = servletContext.getMimeType("/1.html"); System.out.println(mimeType); ~~~ ## 資源共享 設置 ~~~ ServletContext servletContext = getServletContext(); Integer count = (Integer) servletContext.getAttribute("count"); if (count == null) { servletContext.setAttribute("count", 1); } servletContext.setAttribute("count", count + 1); ~~~ 獲取 ~~~ ServletContext servletContext = getServletContext(); Object count = servletContext.getAttribute("count"); System.out.println(count); ~~~ 刪除 ~~~ ServletContext servletContext = getServletContext(); servletContext.removeAttribute("count"); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看