The Web. xml rules are summarized as follows:

Source: Internet
Author: User

1. The deployment descriptor file must start with an xml header, just like all XML files. This header declares the XML version that can be used and provides the character encoding of the file.
2. The docytpe statement must appear immediately after this header. This Declaration tells the server the version of the applicable servlet specification (such as 2.2 or 2.3) and specifies the DTD (Document Type Definition, document type definition) that manages the syntax of the remaining part of the file ).
The top-level (Root) element of all deployment descriptor files is web-app. Note that XML elements are case sensitive, Unlike HTML. Therefore, web-app and WEB-APP are invalid, web-app must be in lower case.

1 <? XML version = "1.0" encoding = "UTF-8"?>
2
3 <web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" version = "2.4" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
4
5 </Web-app>
6
7

2. deployment descriptor file element order

1 <? XML version = "1.0" encoding = "UTF-8"?>
2
3 <web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" version = "2.4" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
4
5 </Web-app>
6
7

2. deployment descriptor file element order

XML elements are not only case sensitive, but also order sensitive to other elements.

The xml header must be the first item in the file, the doctype Declaration must be the second item, and the Web-app element must be the third item. In web-app elements, the order of elements is also important. Servers do not necessarily require this order, but they allow (in fact some servers do this) to completely reject the execution of Web applications that contain elements with incorrect order. This indicates that the Web. xml file with non-standard element order cannot be transplanted.

The following list shows the order of all valid elements that can directly appear in the Web-app element.

This list indicates that the servlet element must appear before all servlet-mapping elements. Note that all these elements are optional. Therefore, an element can be omitted, but it cannot be placed in an incorrect position.
The icon element indicates the location of one or two image files of a Web application using IDE and GUI tools.
L display-name element provides a GUI tool that may be used to mark the name of a specific web application.
L The description Description element provides descriptive text related to this.
L The context-Param element declares the initialization parameters within the application range.
L The filter element associates a name with a class that implements the javax. servlet. Filter interface.
L once a filter-mapping is named, the filter-mapping element should be used to associate it with one or more servlet or JSP pages.
L The Listener servlet API Version 2.3 adds support for event listening programs. The event listening program is notified when the session or servlet environment is created, modified, and deleted. The listener element specifies the event listener class.
L servlet must first name the servlet or JSP page when setting initialization parameters or custom URLs to the servlet or JSP page. The servlet element is used to complete this task.
L The servlet-mapping server generally provides the servlet with a default URL: http: // host/webappprefix/servlet/servletname. However, this URL is often changed so that the servlet can access initialization parameters or process relative URLs more easily. When you change the default URL, use the servlet-mapping element.
L session-config if a session is not accessed for a certain period of time, the server can discard it to save memory. You can use the setmaxinactiveinterval method of httpsession to explicitly set the timeout value for a single session object, or use the session-config element to specify the default timeout value.
L mime-mapping the mime-mapping element provides this guarantee if the web application wants to assign specific MIME types to special files.
L The Welcom-file-list welcome-file-list element indicates which file the server uses when it receives a URL that references a directory name rather than a file name.
L The error-page element allows you to specify the page to be displayed when a specific HTTP status code is returned or an exception of a specific type is thrown.
L The taglib element specifies an alias for the tag library descriptor file (TAG libraryu descriptor file. This feature allows you to change the location of TLD files without editing the JSP pages that use these files.
L The resource-env-ref element declares a resource-related management object.
L The resource-ref element declares the external resources used by a resource factory.
L The Security-constraint security-constraint element specifies the URL to be protected. It is used together with the login-config element.
L login-config uses the login-config element to specify how the server grants permissions to users attempting to access protected pages. It is used with the sercurity-constraint element.
L The Security-role security-role element provides a list of security roles that appear in the role-name sub-element of the security-role-ref element in the servlet element. Declaring roles separately makes it easier for advanced ide to process security information.
L The env-entry element declares the environment items of the Web application.
L The EJB-ref element declares a reference to the main directory of an EJB.
L The EJB-local-ref element declares the application of the local main directory of an EJB.

 

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.