Call Servlet to process requests
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>: Servlet name, which is unique.
<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> *: defines Servlet initialization parameters.
<Description> *: Initialize the parameter text description.
<Pararm-name>: name of the initialization parameter.
<Param-value>: 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, which is unique and consistent. 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 the request is successful, the Servlet is called to process the request. 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 are successful, the container will ask the WEB application to call Servlet to process the request. If no default Servlet is defined, the container will send the 404 request to the client because the resource does not exist.
- Scala Servlet in Scala Language
- Servlet API Discussion
- Introduction to Servlet containers and Context
- Servlet Source file to Class Process
- Details about Listener listening to Http sessions