Web. XML (Deployment Descriptor deployment Profile) configuration instructions in the Eclipse:java project

Source: Internet
Author: User

Context-param, listener, filter, servlet

The first thing to be sure is that the order of loading is independent of their order in the Web. XML configuration file. That is, the filter is not loaded before the filter is written in front of the listener. The final conclusion is: Listener, filter, servlet

There is also a configuration section: Context-param, which provides a key-value pair to ServletContext, which is the initialization parameter for the application context. Our listener, filter, and so on are initialized with the information in these contexts, so should the Context-param configuration section be written before the Listener configuration section? In fact, the Context-param configuration section can be written in any location. However, the real load order is: servlet, listener, filter, Context-param

For multiple configuration items of a certain class of configuration nodes, it is related to the order in which they appear. In the case of filter, it is possible to define multiple filter in Web. XML, a configuration node related to filter is filter-mapping, it is important to note that for filter and fil with the same filter-name Ter-mapping the configuration section, filter-mapping must appear after the filter, otherwise the filter-name it corresponds to is undefined when it resolves to filter-mapping. When each filter is initialized at the start of the Web container, 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 invoked in the order in which the Filter-mapping configuration section appears in sequence D The Ofilter () method.

The servlet is similar to filter and is not mentioned here.

From this, it can be seen that the loading order of Web. XML is: Context-param---listener, filter--, and the sequence of actual program calls between the same types is based on the order of the corresponding mapping. Called by

Context-param
配置的是整个web应用的上下文初始化参数。
    <context>        <param-name></param-name>        <param-value></param-value>    </context>

If you want to get the parameter value, you can call it in the servlet:
(1) Getservletcontext.getinitparameter ("");
(2) Getservletconfig (). Getservletcontext (). Getinitparameter ();
After the Web app deployment is complete, the value cannot be changed.

Listener

<listener>

<listener-class></listener-class>

</listener>

web容器自己会根据listener-class中的类implements什么类型的接口进行判断。
Filter
 <filter>     <filter-name></filer-name>     <filer-class></filer-class>     <init-param>         <param-name></param-name>         <param-value></param-value>     </init-param> </filter><filer-mapping>    <filer-name></filer-name>    <url-pattern></url-pattern></filer-mapping>
    • The filer has two configuration nodes: Filer and filer-mapping, where the corresponding filer-mapping must be configured after the filer configuration node is configured. The mapping of filer-mapping can be based on: Url-pattern, similar to servlet-mapping. or use it directly.
servlet
 <servlet>     <servlet-name></servlet-name>     <servlet-class></servlet-class>     <init-param>         <param-name></param-name>         <param-value></param-value>     </init-param>     <init-param>         <param-name></param-name>         <param-value></param-value>     </init-param>     <load-on-startup></load-on-startup> </servlet><servlet-mapping>    <servlet-name></servlet-name>    <url-pattern></url-pattern></servlet-mapping>
    • Init-param: The configured Key/value is set to the ServletConfig object that corresponds to the servlet. Note: Unlike Servletcontxt, each servlet

will have their own servletconfig. When the deployment is complete, the parameter values cannot be changed.
?? Load-on-startup: Used to determine the load time of the servlet. If not set or negative, the servlet class is loaded and init () is called when the first user request corresponding to the servlet arrives. If positive or 0, the servlet is loaded after the Web app is deployed. The size of the numbers also identifies the order in which they are loaded, and the smaller the value, the earlier it is loaded, and if the values are equal, first loaded in the Web. XML declaration.

Session-config (Session time-out setting, per minute)
 <session-config>     <session-timeout></session-timeout> </session-config>
    • If a session is not accessed for a certain amount of time, the server can discard it to save memory. You can explicitly set a time-out value for a single Session object (in seconds) by using the HttpSession Setmaxinactiveinterval method, or you can use the Session-config element to make a default timeout value (in this case, the branch).

Web. XML (Deployment Descriptor deployment Profile) configuration instructions in the Eclipse:java project

Related Article

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.