web.xml configuration arranged effect
- WEB start a project, containers (such as: Tomcat) will read its configuration file web.xml read two nodes: and
2. Then, create a container ServletContext (context), all parts of this project will be WEB sharing this context.
3. the key-value pair into the vessel, and to the ServletContext.
class instance created in the container 4., i.e., creates a listener.
5. there will contextInitialized (ServletContextEvent args) listening initialization method, in this method = ServletContextEvent.getServletContext obtain the ServletContext ();
context-param value = ServletContext.getInitParameter ( "context-param key");
6. get this value context-param after, you can do something a note. this time your WEB project has not been fully completed to start. this action will be earlier than all of the Servlet.
in other words, this time you do on the key operation and will be in full before you start the project WEB execution.
7. For example you may want to open before the start of the project database.
so here you can set up connections in the database, in class listening to initialize the database Connect
8. This monitor is to write a class, in addition to the initialization method, it also destroyed a method for releasing resources before closing the application example, close the database connection...
Such as: