Web. XML load Order

Source: Internet
Author: User

Web. XML load Order Application Server start-up when the web.
Yes, but there are application servers, and I've met WebSphere that's strict with Web. xml
Node order, otherwise the deployment is unsuccessful, so it is still in favor of writing in the Web. XML standard format
Content-param---listener----servlet 1, when you start a Web project, the application server reads its configuration file Web. Read two sections
Point:<listener></listener> and <context-param></context-param>

2, immediately after the container creates a servletcontext (context), all parts of this web project will be
Share this context.

3, the container will <context-param></context-param> into a key value pair, and give
ServletContext.

4, the container creates the class instance in <listener></listener>, namely creates listens.

5, in the monitoring will have contextinitialized (Servletcontextevent args) initialization method, in this
A method to obtain the
ServletContext = Servletcontextevent.getservletcontext ();
The value of Context-param = Servletcontext.getinitparameter ("Context-param key
");

6. After you get the value of this context-param, you can do something about it. Note that this time you
The Web project has not been fully started yet. This action will be earlier than all servlets. In other words,
By this time, you will be doing the key values in <context-param>, the Web project is fully
Be executed before the project is started. If you want to open the database before it starts, you can
<context-param> sets the connection of the database in the Listener class to initialize the connection to the database, which
A listener is a class that writes itself, in addition to the initialization method, it also has the method of destroying. Used to close the pre-release of the app
Resources. For example, the database connection is closed.
is related to the order in which they appear for a certain type of configuration section.
Take filter as an example Web. XML can of course define multiple filter-related configurations
Section is filter-mapping here, it is important to note that for the same filter-name filter and
Filter-mapping configuration section, filter-mapping must appear after the filter otherwise when parsing
To Filter-mapping, its corresponding filter-name has not yet been defined.
When each filter is initialized when the Web container starts, it is initialized in the order in which the Filter configuration section appears, and when the request resource matches multiple filter-mapping, the filter interception resource is followed by the
The Filter-mapping configuration section appears in order to call the DoFilter () method in turn.
Servlets like filter are not mentioned here. For example, the filter needs to use the bean but the load order is to load the filter and load the spring filter
The bean in the initialization operation is null so if a bean is to be used in the filter
How spring loads change to listener
<listener>
<listener-class>org.springframework.web.context.contextloaderlistener</
Listener-class>
</listener> Web. XML node parsing

Root node
1, <web-app></web-app> common node Introduction
2, <context-param/> Used to set the Web platform environment parameters
It consists of two child elements
<param-name></param-name> the name used to specify the parameter
<param-value></param-value> to set parameter values
The parameters set here can be used in the servlet
Getservletcontext (). Getinitparameter ("My_param") to obtain
Example:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath*:/log4j.properties</param-value>
</context-param>

3, <listener/> Used to set the listener interface
Its primary child element is the
<listener-class></listener-class> defining class names for listener
Example:
<listener>
<listener-class>org.springframework.web.context.contextloaderlistener</
Listener-class>
</listener>
4. <filter/> is used to declare the relevant settings of filter
<filter-name></filter-name> of course it's the name of the filter.
<filter-class></filter-class> This is the name of the class used to define the filter
<init-param></init-param> used to define a parameter it has two child elements
<param-name></param-name> the name used to specify the parameter
<param-value></param-value> to set parameter values
Example:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.characterencodingfilter</filter-cl
Ass>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

5. <servlet/> is used to declare the data for a servlet to have the following child elements
<servlet-name></servlet-name> Specify the name of the servlet
<servlet-class></servlet-class> specifying the class name of the servlet
<jsp-file></jsp-file> Specify the full path of a JSP Web page in the Web platform
<init-param></init-param> used to define parameters and the previous <init-param> almost
Also used in conjunction with <servlet></servlet> is
<servlet-mapping></servlet-mapping> is used to define the URL for the servlet that contains
Two child elements
<servlet-name></servlet-name> Specify the name of the servlet
<url-pattern></url-pattern> Specify the URL for the servlet
<servlet>
<servlet-name>DemoServlet</servlet-name>
<servlet-class>com.test.DemoServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>DemoServlet</servlet-name>
<url-pattern>/demoServlet</url-pattern>
</servlet-mapping> Basic node:

6, <description/> is a description of the platform
Examples <description> preaching, tuition, and doubts </description>

7, <display-name/> define the name of the platform
Example <display-name> My Site </display-name>

8. <icon>
The icon element contains the Small-icon and Large-icon two child elements. Used to specify a small web platform icon
and the path of the large icon.
<small-icon>/Path/smallicon.gif</small-icon>
The Small-icon element should point to the path of a small icon in the Web platform, which is a size of X pixel, but
The image file must be in GIF or JPEG format, and the extension must be:. gif or. jpg.
<large-icon>/Path/largeicon-jpg</large-icon>
The Large-icon element should point to a large chart path in the Web platform, with a size of X pixel, but the figure
Image file must be in GIF or JPEG format, the extension must be; GIF or JPG.
Example:
<icon>
<small-icon>/images/small.gif</small-icon>
<large-icon>/images/large.gir</large-icon>
</icon>

9, <distributable/> is to specify whether the platform can be distributed processing

10, <session-config/> used to define the session parameters in the Web platform
Contains a child element
<session-timeout></session-timeout> is used to define all sessions of this web platform
The validity period unit is minutes 11, <mime-mapping/> Defines an extension and a certain MIME type to do the right should
Consists of two child elements
<extension></extension> extension name <mime-type></mime-type> MIME format
Example
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping> 12, <error-page>
<error-page>
<error-code>500</error-code>
<location>/message.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/message.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/message.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/message.jsp</location>
</error-page>
<error-page>
<error-code>502</error-code>
<location>/index.jsp</location>
</error-page>

13. <jsp-config/>
<jsp-config>
<taglib>
<taglib-uri>/struts-tags</taglib-uri> <taglib-location>/web-inf/struts-tags.tld</ Taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-dojo-tags</taglib-uri>
<taglib-location>/WEB-INF/struts-dojo-tags.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/s</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
</jsp-config>

14. <welcome-file-list/>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

15. <resource-ref></resource-ref> define the resources available to the platform using Jndi
There are five child elements
<description></description> Resource Description
<rec-ref-name></rec-ref-name> Resource Name
Types of <res-type></res-type> Resources
<res-auth></res-auth> resources licensed through application or container
Whether <res-sharing-scope></res-sharing-scope> resources can be shared with shareable
and unshareable two values default to shareable such as configuring the database connection pool can be configured here
<resource-ref>
<description>jndi JDBC DataSource of shop</description>
<res-ref-name>jdbc/sample_db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Web. XML load Order

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.