☰ See All Chapters |
What is deployment descriptor - web.xml file
A web application's deployment descriptor maps the http request with the servlets. When the web server receives a request for the application, it uses the deployment descriptor to map the URL of the request to the code that ought to handle the request. The deployment descriptor should be named as web.xml. It resides in the application's WAR file under the WEB-INF/ directory. Root element of web.xml should be <web-app>. <servlet> element map a URL to a servlet using <servlet-mapping> element. To map a URL to a servlet, you declare the servlet with the <servlet> element, then define a mapping from a URL path to a servlet declaration with the <servlet-mapping> element. The <servlet> element declares the servlet class and a logical name used to refer to the servlet by other elements in the file. You can declare multiple servlets using the same class but name for each servlet must be unique across the deployment descriptor. The <servlet-mapping> element specifies a URL pattern and the name of a declared servlet to use for requests whose URL matches the pattern. The URL pattern can use an asterisk (*) at the beginning or end of the pattern to indicate zero or more of any character. The standard does not support wildcards in the middle of a string, and does not allow multiple wildcards in one pattern. The pattern matches the full path of the URL, starting with and including the forward slash (/) following the domain name. The URL path cannot start with a period (.).
All Chapters