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

Koray Tugay picture Koray Tugay · Apr 13, 2013 · Viewed 43.1k times · Source

In a java web application, there is a file called web.xml and it has a versioning.

What exactly is this? What is it used for?

Here is the SO wiki for web.xml. But it does not really explain me much.

It allows you to define, declare and configure the Servlet API based implementations in your web application, such as servlets, filters and listeners.

Sample web.xml versioning:

<web-app 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"
         version="3.0">

Can someone explain this with simple examples perhaps?

Answer

Miljen Mikic picture Miljen Mikic · Apr 13, 2013

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

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: