Context-param Triggers the association of the spring container and the servlet container

Source: Internet
Author: User
Tags format definition

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.