Friday, 7 June 2013

Java Deployment Descriptor: web.xml

When deploying a Java web application, arguably the single most important file is the deployment descriptor. It's sole purpose is to describe to the container (the server you're deploying your application on e.g. Tomcat, JBoss, Websphere..) exactly how to deploy the application. It defines a bunch of core information on how your application will be accessed by users.

 The following is the most basic valid web.xml file for a Servlet 3.0 J2EE Web Application.




        3.0 WebApp


We can extend this by adding a 'welcome file'. This is exactly what it claims to be - it's the file that will be displayed when the application is successfully deployed and a user tries to access it. What we're saying here is that if a user accesses the root path of the web application (for example, http://:/ ) they will be presented with 'index.html'. This is a very basic way of providing an entry-point to your application, but is a great way of testing whether or not the application deployment has been successful.



  3.0 WebApp

  
    index.html
  


This is very, very basic stuff, but understanding how the deployment descriptor works is key to a bunch of more interesting stuff, including Servlets and the Spring MVC framework.

No comments:

Post a Comment