Servlet/JSP Container development NOTE 3-processing of ServletMapping

Source: Internet
Author: User

Note: The following urls do not contain ContextPath.

Servlet ing URL specification

1. Indicates path ing starting with/and ending with/*, that is,/Test/* indicates that the request path starts with/Test/is mapped to the Servlet for processing.
2. Extension ing starting with *. That is, *. abc indicates that all requests with abc extension are mapped to the Servlet for processing.
3. Start with/to indicate full ing, that is,/Test indicates that the request URL is/Test mapped to the Servlet for processing.
4. If the URL Pattern is/, it is mapped to the default Servlet. When other URL mappings do not match, the default Servlet is used.


Path Matching Sequence

1. First match the fully mapped URL
2. re-match the URL mapped to the path, and the longest path is matched first.
3. re-match the extension ing
4. Use the default Servlet.

The following is an example

Servlet ing

Path pattern servlet

/Foo/bar/* servlet1
/Baz/* servlet2
/Catalog servlet3
*. Bop servlet4

Incoming path servlet handling request

/Foo/bar/index.html servlet1
/Foo/bar/index. bop servlet1
/Baz servlet2
/Baz/index.html servlet2
/Catalog servlet3
/Catalog/index.html "default" servlet
/Catalog/racecar. bop servlet4
/Index. bop servlet4

ServletPath and PathInfo in various matching Modes

1. fully match ServletPath = matching pattern PathInfo = null
2. The extension matches ServletPath = the requested URL PathInfo = null.
3. Path match ServletPath = match mode cut "/*" PathInfo = request URL cut ServletPath
4. By default, Servlet matches ServletPath = requested URL PathInfo = null

If the same URL is mapped to multiple Servlets, The Serlvet specification is not described. tomcat (a very useful JSP running platform) uses the last mapped Servlet.
If the Servlet ing in the container is overwritten, use the new ing.

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.