Tag: Key value instance des resource Name style order font context
<context-param>
<param-name></param-name>
<param-value>></param-value>
</ Span class= "Tag-name" style= "margin:0px; padding:0px; Color: #993300; " > 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 the value of the parameter name set
- when you start a Web project, the container (such as Tomcat) Read the two nodes <listener> and <contex-param> in the Web. XML configuration file.
- The container then creates a ServletContext (context) that can be used by the entire Web project within the scope of the application.
- The container then converts the read to <context-param> into a key-value pair and gives it to ServletContext. The
- container creates a class instance in <listener></listener>, That is to create a listener (note: Listener defined classes can be custom classes but must inherit Servletcontextlistener). The
- has a contextinitialized (Servletcontextevent event) initialization method in the listening class, which can be passed Event.getservletcontext (). 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
- On the page
${initparam.contextconfiglocation}
- In the servlet
String Paramvalue=getservletcontext (). Getinitparameter ("contextconfiglocation")
Web. XML configuration Detailed Context-param