Look at Java EE version. Servlet (and JSP, JSF, EJB, JPA, etc) version goes hand in hand with Java EE version.
- Java EE 8 = Servlet 4.0
- Java EE 7 = Servlet 3.1
- Java EE 6 = Servlet 3.0
- Java EE 5 = Servlet 2.5
- J2EE 1.4 = Servlet 2.4
- J2EE 1.3 = Servlet 2.3
- J2EE 1.2 = Servlet 2.2
Look at the server homepage/documentation how it presents itself. For GlassFish, that is currently (with 4.1):
World's first Java EE 7 Application Server
So, it's Servlet 3.1.
But, with a big but, that's one thing. The second thing is, the webapp's web.xml
version also plays a role. Not everyone knows that.
If your webapp's web.xml
is declared conform Servlet 3.1 like below,
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Config here. -->
</web-app>
then your webapp will also really run in Servlet 3.1 modus.
However, if it's declared conform Servlet 3.0 like below or even older,
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Config here. -->
</web-app>
then your webapp will run in Servlet 3.0 compatibility modus, even when deployed to a Servlet 3.1 compatible container! The above influences the ServletContext#getMajorVersion()
and getMinorVersion()
, so they actually say nothing about the container, but only about the webapp itself.
If your webapp's web.xml
contains a <!DOCTYPE>
, regardless of the DTD and the version, then it will run in Servlet 2.3 compatibility modus, even when there's a newer XSD declared!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd">
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- This is WRONG! The DOCTYPE must be removed! -->
</web-app>