About the configuration deployment descriptor in the Java Web App. xml

Source: Internet
Author: User
Tags event listener

A Web. XML overview

The Web. xml file that is located under the Web-inf path for each of the websites is called the configuration descriptor, which is important for Java Web applications, and each Java Web application must contain an Web. xml file and must be placed under the Web-inf path.

For Java Web Apps, Web-inf is a special folder, and the WEB container contains the contents of that folder, and the client browser cannot access anything under the Web-inf path.
The vast majority of Java Web applications are configured for management by the. xml file. The following sections, which we describe below, are configured to be managed through the Web. xml file:

(1) Configure the JSP.

(2) Configuring and managing Servlets.

(3) Configure and manage listener.

(4) Configure and manage the filter.

(5) Configure the tag library.

(6) Configure JSP properties.

In addition, Web. XML is also responsible for configuring and managing the following common content:

(7) Configure and manage Jaas authorization authentication.

(8) Configure and manage resource references.

(9) Configure the Web application home page.

For example, configuring the home page in the Web. xml file uses the Welcome-file-list element, which can contain more than one welcome-file child element, each of which is configured with a first page welcome-file child elements. For example, the following configuration fragment:

<!--Configure your Web app's first page 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>

The above configuration information specifies that the first page of the Web app is index.html, Index.htm and index.jsp, meaning: When the Web application contains index.html pages, if the browser directly access the Web application, the system will render the page to the browser, when the index.html page does not exist, then the index.htm page as the homepage, and so on.

Each Web container will provide a system. xml file that describes the common configuration properties for all Web applications. For example, Tomcat's system Web. XML is placed under the Conf path of Tomcat, while the jetty system Web. xml file is placed under Jetty's etc path, and the file name is Webdefault.xml.

Two Specific element description

1 defining headers and root elements
The deployment descriptor file, like all XML files, must start with an XML header. This header declares the XML version that can be used and gives the character encoding of the file.
The DOCTYPE declaration must immediately appear after this header. This statement tells the server which version of the servlet specification is applicable (for example, 2.2 or 2.3) and specifies a DTD (document type definition, doc-types definitions) that manages the syntax for the remainder of this file.
The top-level (root) element of all deployment descriptor files is Web-app. Note that XML elements are not like HTML, and they are case-sensitive. Therefore, Web-app and Web-app are not legal, web-app must be lowercase.

2 element order within the deployment descriptor file

Within the Web-app element, the order of the elements is also important. Servers do not necessarily enforce this order, but they allow (in fact some servers do) a complete denial of the execution of Web applications that contain elements that are not in the correct order. This means that the Web. xml file using the non-standard element order is not portable.
The following list gives all the necessary order for the legitimate elements to appear directly within the Web-app element. For example, this list illustrates that a servlet element must appear before all servlet-mapping elements. Please note that all of these elements are optional. Therefore, you can omit an element, but you cannot put it in an incorrect position.

(1) The Icon:icon element indicates the location of the IDE and GUI tools used to represent one and two image files of the Web application.

(2) The GUI tools provided by the Display-name:display-name element may be used to mark a name for this particular Web application.

(3) The Context-param:context-param element declares the initialization parameters within the scope of the application.

(4) The Filter:filter filter element associates a name with a class that implements the Javax.servlet.Filter interface.

(5) Filter-mapping: Once a filter is named, it should be associated with one or more servlet or JSP pages using the filter-mapping element.

(6) Version 2.3 of the Listener:servlet API adds support for event listeners, which are notified when a session or servlet environment is established, modified, and deleted by the event listener. The listener element indicates the event listener class.

(7) Servlet: You must first name a servlet or JSP page when you make initialization parameters or custom URLs to a servlet or JSP page. The servlet element is used to accomplish this task.

(8) Servlet-mapping: The server typically provides a default URL for the servlet:http://host/webAppPrefix/servlet/ServletName. However, this URL is often changed so that the servlet can access the initialization parameters or make it easier to handle relative URLs. Use the servlet-mapping element when changing the default URL.

(9) 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 by using the Setmaxinactiveinterval method of HttpSession, or you can use the Session-config element to make a default timeout.

Mime-mapping: The mime-mapping element provides this assurance if the Web app has a special file that you want to guarantee to assign a specific MIME type to.

(one) The Welcom-file-list:welcome-file-list element indicates which file the server uses when it receives a URL that references a directory name instead of a file name.

The Error-page:error-page element enables the page to be displayed when a specific HTTP status code is returned, or when a particular type of exception is thrown.

The taglib:taglib element specifies an alias for the tag Library descriptor file (tag Libraryu descriptor files). This feature enables you to change the location of TLD files without editing the JSP pages that use those files.

The Resource-env-ref:resource-env-ref element declares a management object that is associated with a resource.

The Resource-ref:resource-ref element declares an external resource used by a resource factory.

() The Security-constraint:security-constraint element formulates the URL that should be protected. It is used in conjunction with the Login-config element.

Login-config: Use the Login-config element to specify how the server should authorize users attempting to access a protected page. It is used in conjunction with the Sercurity-constraint element.

The Security-role:security-role element gives a list of security roles that will appear in the Role-name child elements of the security-role-ref element within the servlet element. Declaring roles separately makes it easier for advanced Ides to handle security information.

The Env-entry:env-entry element declares the environment item for the web App.

The Ejb-ref:ejb-ref element declares a reference to the home directory of an EJB.

The Ejb-local-ref:ejb-local-ref element declares the application of an EJB's local home directory.

About the configuration deployment descriptor in the Java Web App. xml

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.