Martini package deployment descriptor
In Java EE, the deployment descriptor file /WEB-INF/web.xml
describes how an
application should be deployed to a servlet container like Tomcat, Jetty, or JBoss. The
aforementioned file defines the servlets that exist in the web application (via <servlet>
tags) and specifies which
servlet the container should use according to the URL mapping being accessed (supported mappings by the servlet are
defined in <servlet-mapping>
elements)1.
Example web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
In the configuration above, a DispatcherServlet
is declared and mapped as the default
and only servlet2 of the web application. The DispatcherServlet
is Spring MVC's front controller; its job is to
take an incoming request and delegate the request to the right handler(s) so that the request can be processed and
the server could respond appropriately. Since it is the default and only servlet in the configuration above, it will
be handling all requests received by the container; which is also the case in most Spring MVC-based
web applications.
Once a Martini package's web
directory exists, even if it's empty, Martini will treat that package as a
separate web application. Furthermore, it is possible to create your own custom /WEB-INF/web.xml
and override
the default /WEB-INF/web.xml
Martini creates for you if your package's /WEB-INF/web.xml
does not exist in the
web
directory.
The web
directory does not exist by default
Creating a package does not automatically create the package's respective web
directory.
To create a new directory inside your package,
right click your package from the Navigator,
and then select New > Folder. Your package must be loaded to allow this action.
Why would I want to create my own /WEB-INF/web.xml
file?
Customizing a package's deployment descriptor is not required; in fact, TORO recommends leaving it empty unless
you want to customize behavior. However, creating your own custom /WEB-INF/web.xml
enables you to configure
advanced behavior for your web application via adding things such as other filters and
servlets.
Procedure
- Create the Martini package's
web
directory, if it doesn't exist yet. -
Create the
/WEB-INF
directory under theweb
directory, and then create and define theweb.xml
file under/WEB-INF
.Other configuration files may be required
Depending on the web application configuration you're going for, there may be other configuration files required. For example, if you have defined a context parameter named
contextConfigLocation
whose value is/WEB-INF/root-configuration.xml
, then this file must exist. -
After finalizing your configuration files, restart the package in order to reflect your changes.
-
Sheng. (2015, August). Understand web.xml in Spring MVC project [Blog post]. Retrieved from http://shengwangi.blogspot.com/2015/08/understand-webxml-in-spring-mvc-project.html ↩
-
/
, being the servlet's URL pattern, indicates that it is the default servlet of the web application. ↩