Transferred from: http://blog.csdn.net/liaoxiaohua1981/article/details/6759206
Format definition: [HTML] View plaincopy<Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Contextconfiglocationvalue></Param-value> </Context-param>
role: This element is used to declare context initialization parameters within the scope of the application (the entire Web project). Param-name sets the parameter name of the context. Must be a unique name Param-value sets the value initialization process for parameter names: When you start a Web project, a container (such as Tomcat) reads two nodes in the. XML configuration file < listener > and < contex-param > < context-param Span style= "color: #0000ff;" >> converts to key-value pairs and gives ServletContext. Container creation < listener ></ listener > The class instance in the Create listener (note: The class defined by listener can be a custom class but must inherit Servletcontextlistener). There is a contextinitialized (Servletcontextevent event) initialization method in the listener class, which can be passed Event.getservletcontext () in this method. Getinitparameter ("Contextconfiglocation") to get the value Context-param set. There must also be a contextdestroyed (Servletcontextevent event) Destruction method in this class. To release resources before closing the app, such as closing the database connection. After you get the value of this context-param, you can do something about it. Note that this time your Web project is not fully started yet. This action will be earlier than all servlets. By the above initialization process, it is known that the container loading process for Web. XML is context-param >> listener >> fileter >> servlet
How to use the ${initparam.contextconfiglocation}servlet string in the page Paramvalue=getservletcontext (). Getinitparameter (" Contextconfiglocation ")
Context-param Triggers the association of the spring container and the servlet container