"Web. XML configuration specific explanation of the Context-param"

Source: Internet
Author: User
Tags format definition

Transferred from: http://blog.csdn.net/liaoxiaohua1981/article/details/6759206
    • Format definition:
[HTML]View Plaincopy
  1. < context-param >
  2. <Param-name>contextconfiglocation</Param-name>  
  3. <Param-value>Contextconfiglocationvalue></Param-value>  
  4. </ context-param >

Role: This element is used to declare the 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 set the value of the name of the parameter

    • Initialization process:
      1. when you start a Web project, the container (for example, Tomcat) Read the two nodes <listener> and <contex-param> in the Web. XML configuration file.
      2. The container then creates a ServletContext (context) that can be used by the entire Web project within the scope of the application.
      3. The container then converts the read to <context-param> into a key-value pair and gives it to ServletContext. The
      4. container creates a class instance in <listener></listener>, That is to create a listener (note: The class defined by listener can be a class of its own definition but must inherit Servletcontextlistener). The
      5. 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. Frees resources before closing the app, such as the shutdown of a database connection.
      6. After you get the value of this context-param, you can do something about it. Note that your Web project is not fully started at this time. This will be earlier than the entire servlet.

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
    1. On the page

      ${initparam.contextconfiglocation}

    2. In the servlet
      String paramvalue=getservletcontext (). Getinitparameter ("contextconfiglocation")

Disclaimer: This content is collated

"Web. XML configuration specific explanation of the Context-param"

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.