within a specific <servlet> element web
Servlet init parameters在web.xml中以下 tomcat
<servlet> app
<servlet-name> webapp
BeerParamTestsspecific servlet jsp
經過這樣的代碼獲取ServletContext ide
getServletContext().getInitParameter(「foo」); this
經過這樣的代碼獲取ServletConfig xml
getServletConfig().getInitParameter(「foo」); ci
Availability
To any servlets and JSPs that are part element
of this web app.(ServletContext是對於任何的jsp或者servlet都是有效的,能夠訪問的)
widely available by storing it in an attribute.)
(ServletConfig對於特定配置好<inti-param>的servlet有效)
對於每個servlet都有一個servletConfig
對於整個webapp有一個ServletContext
當web app初始化的時候,容器(好比tomcat)讀取web.xml,而且爲<context-param>建立一個鍵值對,
容器建立一個新的ServletContext實例,
容器將鍵值對傳遞給建立好的實例ServletContext
web app中的任何一部分都有訪問這個ServletContext的權限