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
From Servlet 3.0 onwards, Web.xml is optional, You can use @WebServlet
annotation instead.
If you are using Spring, org.springframework.web.WebApplicationInitializer
can be used instead or along with web.xml.
WebApplicationInitializer :
Interface to be implemented in Servlet 3.0+ environments in order to configure the ServletContext programmatically -- as opposed to (or possibly in conjunction with) the traditional web.xml-based approach.
To answer your below question.
What does it affect? (In a Spring application)
web.xml versioning:
However, if WEB-INF/web.xml
is present in the application, its version attribute must be set to "3.0" or greater, otherwise ServletContainerInitializer
bootstrapping will be ignored by the servlet container.
You can read the full java doc of WebApplicationInitializer here.
what i understand from the web.xml esp for the part of web-app version="3.0"
is the version of your servlet. So, i restrict my answer to the servlet version and why it is so important. As you may know version of your servlet controls most of the other standards when you are programming with Java EE.
For example,
JSF 2.0 requires SERVLET 2.5 comes with JAVA EE5 and WEBLOGIC 10.3.X support all these technologies, for other containers you should check the release notes. Secondly, JSF 2.1 requires SERVLET 3.0 comes with JAVA EE6 and WEBLOGIC 12c supports all these technologies. Of course backward compatibility is ensured, however most of the cases it's possible to have some problems.
when we check the weblogic 12c release notes, i starred the most important technologies supported along with the servlet version. i hope this is also useful for you with the great answer of Miljen Mikic.
Standard Version
Contexts and Dependency Injection for Java EE 1.0
Dependency Injection for Java EE 1.0
Expression Language (EL) 2.2, 2.1, 2.0
Only JSP 2.0 and greater supports Expression Language 2.x.
JAAS 1.0 Full
JASPIC 1.0
Java API for XML-Based Web Services (JAX-WS) 2.2, 2.1, 2.0
Java API for RESTful Web Services (JAX-RS) 1.1
Java Authorization Contract for Containers (JACC) 1.4
**Java EE 6.0**
Java EE Application Deployment 1.2
Java EE Bean Validation 1.1
Jave EE Common Annotations 1.0
Java EE Connector Architecture 1.6
Java EE EJB 3.1
Java EE Enterprise Web Services 1.3, 1.2, 1.1
Jave EE Interceptors 1.1
**Java EE JDBC 4.0, 3.0**
Java EE JMS 1.1, 1.0.2b
Java EE JNDI 1.2
**Java EE JSF 2.1, 2.0, 1.2, 1.1**
Java EE JSP 2.2, 2.1, 2.0, 1.2, and 1.1
JSP 1.2. and 1.1 include Expression Language (EL), but do not support EL 2.x or greater.
Java EE Managed Beans 1.0
**Java EE Servlet 3.0, 2.5, 2.4, 2.3, and 2.2**
Java RMI 1.0
JavaMail 1.4
JAX-B 2.2, 2.1, 2.0
JAX-P 1.3, 1.2, 1.1
JAX-R 1.0
JAX-RPC 1.1
JCE 1.4
**JDKs 6.0 (aka 1.6), 5.0 (aka 1.5, clients only)**
JMX 1.2, 1.0
JPA 2.0, 1.0
JSR 77: Java EE Management 1.1
JSTL 1.2
Managed Beans 1.0
OTS/JTA OTS 1.2 and JTA 1.1
RMI/IIOP 1.0
SOAP Attachments for Java (SAAJ) 1.3, 1.2
Streaming API for XML (StAX) 1.0
Web Services Metadata for the Java Platform 2.0, 1.1