Wednesday, March 5, 2014

Java EE / Deployment descriptor (web.xml)

Java: Deployment Decriptor: web.xml

Deployment descriptor describes the classes, resources and configuration of the application
and how the web server uses them to serve web requests.
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 is a file named web.xml.
It resides in the app's WAR under the WEB-INF/ directory.
The file is an XML file whose root element is <web-app>.

Simple example of decriptor:

    
        spring
        org.springframework.web.servlet.DispatcherServlet
    
    
        spring
        *.html
    


Descriptor defines mappings between URL paths and the servlets that handle requests with those paths.
The web server uses this configuration to identify the servlet to handle a given request
and call the class method that corresponds to the request method.

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 pattern matches the full path of the URL, starting with and including the forward slash (/) following the domain name.

More details for example here.

No comments: