web.xml的配置中<context-param>配置作用
1. 啓動一個WEB項目的時候,容器(如:Tomcat)會去讀它的配置文件web.xml.讀兩個節點: <listener></listener> 和 <context-param></context-param>
context-param的值 = ServletContext.getInitParameter("context-param的鍵");
換句話說,這個時候,你對<context-param>中的鍵值做的操作,將在你的WEB項目完全啓動之前被執行.
那麼這裏就可以在<context-param>中設置數據庫的連接方式,在監聽類中初始化數據庫的連接.
< !-- 加載spring的配置文件 -->
< context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,/WEB-
< /context-param>
< listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
< /listener>