In servlet programming every servlet is identified with it’s servlet URL pattern. Clients, other webresource programs, containers identify servlet program through servlet URL mapping. This URL pattern is useful to hide the servlet class name and the technology of web application from outsiders.
To specify a servlet through the URL pattern there are three types of URL patterns. All servlet containers servers must be designed support these URL patterns. They are
a)Exact match URL pattern.
b)Direct match URL pattern.
c)Extension matches URL pattern.
Eg. In “web.xml” file we specify the url-pattern as
"/abc"
"/abc.c"
"/x/y/abc.cpp"
Eg. . In “web.xml” file we specify the url-pattern as "/xy/zx/*"
Eg. In “web.xml” file we specify the url-pattern as "*.ab"
Note:
To specify a servlet through the URL pattern there are three types of URL patterns. All servlet containers servers must be designed support these URL patterns. They are
a)Exact match URL pattern.
b)Direct match URL pattern.
c)Extension matches URL pattern.
Exact match URL pattern:
This type of URL patterns must begin with “/” symbol and must not contain “*” symbol. Observe the below examples to understand the exact match URL patterns.Eg. In “web.xml” file we specify the url-pattern as
"/abc"
"/abc.c"
"/x/y/abc.cpp"
Request URL’s:
Direct match URL pattern:
This URL pattern must begin with “/” and must end with “*” symbol. The modification done in “web.xml” file will be recognized by underlying server automatically because servers internally reload the web application. We can provide URL patterns for both servlet, JSP programs to hide their filenames and extensions from the visitors of the website. To understand this with the below examples.Eg. . In “web.xml” file we specify the url-pattern as "/xy/zx/*"
Request URL’s:
Extension matches URL patterns:
This URL pattern must begin with “*” symbol having extensions.This type of URL mapping is executed based on the "*" so that after the extension must be matched in the URL request of user when ever the user try to give request without after the extension then it gives error.Eg. In “web.xml” file we specify the url-pattern as "*.ab"
Request URL’s:
Note:
- We give a wrong URL pattern in “web.xml” file the whole web application automatically goes to stop mode.
- We give more than one URL pattern to a same servlet program belonging the same or different styles of these patterns.