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.