What exactly is the web-app version? What does it affect?

Web.xml is a central place where you define the configuration of your Web application. For instance you can specify there:

  • servlet mapping, i.e. which URL path refers to which Java class (e.g. when user types http://something.com/Koray you can point that request to KorayServlet.java class where you keep the implementation of the servlet)
  • authorization parameters, e.g. that user Tugay has access to http://something.com/Koray/pictures, but not to http://something.com/Koray/documents
  • all other security settings, e.g. when someone tries to open http://something.com/Restricted, you redirect him to https://something.com/Restricted, i.e. it has to use SSL
  • welcome page of your Web site (e.g. when user types http://something.com/Koray you redirect him to http://something.com/Koray/index.html)

I would also suggest researching Servlet 3.0 specification, where many of these parameters can be set through annotations.

Versioning

Versioning refers to XML schema version that syntax of your web.xml file must obey. More important, it also indicates the version of Servlet specification that your application implements. An example how Servlet 3.0-compliant web.xml should begin:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

Most IDEs will automatically generate that part of web.xml. If you are going to change it manually for some reason, be careful to match the versions of web-app and xsd.

For concrete examples of web.xml, see:

  • web.xml Versioning
  • The deployment descriptor: web.xml
  • Sample Web XML application files

Leave a Comment