Web. xml configuration

Source: Internet
Author: User
The settings of the web. xml parameters and the optional values are.

You can set two parameters in Web. xml.

1. Set parameters in the servlet or filter, for example

<Servlet>
<Servlet-Name> helloworldexample </servlet-Name>
<Servlet-class> helloworldexample </servlet-class>
<Init-param>
<Param-Name> my </param-Name>
<Param-value> You </param-value>
</Init-param>
</Servlet>

Here
Parameter settings are for the helloworldexample servlet. We can use
System. Out. println (this. getinitparameter ("my"); to get the servlet parameters.

2. Global parameters are used for all servlets. The setting method is as follows:

<! -- Test global parameter settings -->
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/classes/META-INF/applicationcontext *. xml </param-value>
</Context-param>

This parameter can be used in all servlets

System. Out. println (getservletcontext (). getinitparameter ("contextconfiglocation "));

To obtain global parameters.

**************************************** **************************************** **************************************** *

Reference

You can also remember.

Context-Param, listener, filter, and Servlet Loading Sequence in Web. xml

Loading Order of different categories: firstContext-Param
ThenListener
NextFilter
LastServlet
.

Similar loading sequence:Based on the mapping order
.

 

Note: The definition must be prior to the corresponding mapping.
.

Http://blog.csdn.net/lwzcjd/archive/2008/10/14/3072971.aspx

**************************************** **************************************** **************************

Servlet instantiation,Filter
Instantiation

Filter is instantiated when the container is started and its init method is executed.

By default, the servlet (<load-on-startup> is not written, or is a negative number) is instantiated by the container when it is requested, and its init method is executed.

In this case, you can use <load-on-startup> 1 </load-on-startup>
Variable: the filter does not have this attribute (I didn't see it when I did it). If this attribute is set in the servlet (it must be a positive number and will not be initialized if it is a negative number), the servlet will
Like filter, it is instantiated when the container is started and its init method is executed.

The greater the value of <load-on-startup>, the lower the instantiation priority. That is, the smaller the value is, the smaller the value is instantiated.
The faster it is. However, even if the servlet sets the <load-on-startup> attribute, that is, when the container is started
The servlet is instantiated before it is instantiated.

 

Since the filter does not have the <load-on-startup> attribute, what is the instantiation sequence of multiple filters?

By default, the bottom filter of Web. XML is first instantiated, that is, the init method of the bottom filter is first executed.
The method is different from the specific call method. The dofilter method is executed in the order of <filter-mapping>.

In addition to the reference section above, all the exercises are obtained, and there may be errors. I also hope to correct them.

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.