Configuration of servlet-mapping URL-pattern in Web. xml

Source: Internet
Author: User

Servlet-mapping provides a URL for the servlet class. You can access your servlet in the address bar, for example:

<Servlet>

<Servlet-Name> helloworld </servlet-Name>

<Servlet-class> com. HX. webfrom. helloworld <servlet-class>

</Servlet>

<Servlet-mapping>

<Servlet-Name> helloworld </servlet-Name>

<Servlet-class>/Hello <servlet-class>

</Servlet-mapping>

Enter http: // localhost: 8080/hello in the address bar.

Tomcat finds mapping in Web. xml by/index. jsp and finds the name:

<Servlet-mapping>

<Servlet-Name> org. Apache. jsp. index_jsp </servlet-Name>

<URL-pattern>/index. jsp </url-pattern>

</Servlet-mapping>



Search for classes by name:

<Servlet>

<Servlet-Name> org. Apache. jsp. index_jsp </servlet-Name>

<Servlet-class> org. Apache. jsp. index_jsp </servlet-class>

</Servlet>



Find Org. apache. JSP. after index_jsp generates an object, it initializes the generated request, response and other objects as parameters/INIT (), and CALLS methods (doget (), dopost ()).

(Many details such as cache and pool are not taken into account, but they do not affect understanding)

When configuring servlet-mapping for Web. XML

Conclusion:

• '/XXX /*'

• '*. Html'

•'/'

• All others are precise ing. For example, '/XXX/y *. html' can only map URL requests of/XXX/y *. html.

For example, '/XXX' can only map/xxx URL requests.

Reference

10.2 specification of Mappings

In the web application deployment descriptor, the following syntax is used to define mappings:

• A string beginning with a'/'character and ending with a'/* 'Postfix is used as a path

Mapping.

• A string beginning with a '*.' prefix is used as an extension mapping.

• All other strings are used as exact matches only

• A string containing only the '/' character indicates that servlet specified by the mapping becomes the "default" servlet of the application.

Translation:

10.2 ing Rule Description

In the Web Application Deployment description (Web. XML), the following syntax structure is used to define the ing:

• A string starting with '/' and ending with '/*' is used for path ing.

• Start with '*.' For extension ing.

• All other strings only perform exact ing.

• A string containing only '/' makes the current servlet the default servlet of the application.

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.