Web. XML configuration Detailed Context-param

Source: Internet
Author: User

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

    • Initialization process:
      1. 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.
      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: Listener defined classes can be custom classes 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. To release resources before closing the app, such as closing the database connection.
      6. 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
      1. On the page

        ${initparam.contextconfiglocation}

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

Web. XML configuration Detailed 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.