Configure the servlet in Web. xml. The servlet is loaded by the web application.

Source: Internet
Author: User

1. The <servlet> element and its child elements declare a servlet.

<Description> *: specify a text description for the servlet.

<Display-Name> *: provides a brief name for the servlet to be displayed by some tools.

<Icon> *: specify an icon for the servlet to represent the servlet in the graphic management tool.

<Servlet-Name>:The name and uniqueness of the servlet.

<Servlet-class> or <JSP-File>: <Servlet-class> is the complete Servlet Path. <JSP-File> specify the full path of the JSP file in the Web application to map the URL of a JSP file.

<Init-param> *:Define servlet initialization parameters.

<Description> *: Initialize the parameter text description.

<Pararm-Name>:The name of the initialization parameter.

<Param-value>:The value of the initialization parameter.

<Load-on-startup>? :The order in which the servlet is loaded when the web application is started. The content is an integer value.

Negative or this element is not set to indicate that the servlet container will load it when the client requests this servlet.

Positive or O indicates that the servlet is initialized from small to large when the web application is started.

If both <JSP-File> elements and <load-on-startup> are included, the JSP file is also pre-compiled and loaded.

<Run-as>? : Role of the Execution Component

<Descripttion>: text description.

<Role-Name>: specifies the role name of the Execution Component.

<Security-role-ref> *: Declares security role references in the code of the component or deployed component.

<Description> *: security role text description.

<Role-Name>: name of the security role used.

<Role-line>? : Specifies a reference to a security role.

 2. The <servlet-mapping> element and its child elements define a ing between the servlet and URL.

<Servlet-Name>:Servlet name, uniqueness and consistency. It is the same as the name declared in the <servlet> element.

<URL-pattern>:Specifies the URL path relative to the servlet. This path is relative to the root path of the Web application context.

3. servlet Loading Process 

The context object of the container processes the Request Path (URL), removes the context path of the request URL, and matches the URL by path ing rules with the servlet ing path (<URL-pattern>, if the matching succeeds, the servlet is called to process the request.

Matching rules: 

The request URL exactly matches. If successful, the servlet is called. Match the longest path prefix. Use/as the path separator to perform step-by-step Matching Based on the path tree. Select the longest matching servlet for processing. If none of the above matches successfully, the container calls the default servlet of the Web application to process the request. If no default servlet is defined, the container will send the 404 error message to the client (the requested resource does not exist.

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.