38

Can you tell me how to know which servlet and JSP version am I using ? I use NetBeans IDE 7.1.2 for creating Servlets and JSP.

Sabapathy
  • 1,613
  • 3
  • 18
  • 30
  • 3
    That should be specified in your web.xml file. – JB Nizet Jun 30 '13 at 07:31
  • The IDE doesn't have anything to do with the JSP and Servlet version of your application. That's declared in the web.xml. – Luiggi Mendoza Jun 30 '13 at 07:32
  • 1
    Check the declarations in your xml files. Also, if you can, check the jars in the classpath of your project. – acdcjunior Jun 30 '13 at 07:32
  • 3
    http://stackoverflow.com/tags/servlets/info – Bhesh Gurung Jun 30 '13 at 07:32
  • @acdcjunior the jars are not the best reference here, since a web application server could handle more than one version of servlets thus accepting wars that use old servlet versions. – Luiggi Mendoza Jun 30 '13 at 07:35
  • @LuiggiMendoza Are you sure? I thought the servlet spec didnt allow that. Anyway, the jars would tell more what is the version the Netbeans project is targeting. – acdcjunior Jun 30 '13 at 07:51
  • @acdcjunior the jars will vary depending on the web application server target (that's why you choose it when creating the project). – Luiggi Mendoza Jun 30 '13 at 07:52
  • @LuiggiMendoza I agree, that's why I thought they could help (if he had chosen servlet 2.5 while creating the project, the corresponding jars should be at the project's classpath). The "are you sure" part was about the server handling more than one version of the servlet-api. – acdcjunior Jun 30 '13 at 07:57
  • As an additional information, in case you are using Tomcat: [The mapping between the Servlet/JSP specifications and the respective Apache Tomcat versions](http://tomcat.apache.org/whichversion.html) – informatik01 Jun 30 '13 at 10:57

3 Answers3

39

You can easily check the JSP,SERVER and SERVLET version. Add the following code in your jsp page after that run using any IDE Tools.

Server Version: <%= application.getServerInfo() %><br>
Servlet Version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %>
JSP Version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %> <br>
David Guyon
  • 2,759
  • 1
  • 28
  • 40
Kannan Arumugam
  • 1,119
  • 2
  • 18
  • 27
22

You can get the details programatically using ServletContext #getMajorVersion() and #getMinorVersion().

For knowing the JSP version corresponding to the Servlet, you can get details from this Tomcat page.

Below is a brief summary (check Tomcat's corresponding version at the link above):

  • Servlet 4.0 uses JSP 2.3
  • Servlet 3.1 uses JSP 2.3
  • Servlet 2.5 uses JSP 2.1
  • Servlet 2.4 uses JSP 2.0
  • Servlet 2.3 uses JSP 1.2
  • Servlet 2.2 uses JSP 1.1
  • Servlet 2.1 uses JSP 1.0
bluish
  • 26,356
  • 27
  • 122
  • 180
Vikas V
  • 3,176
  • 2
  • 37
  • 60
  • 15
    This only returns the max version as **supported** by the servletcontainer. This doesn't return the version currently **used** by the running webapp. This is dictated by `web.xml`. – BalusC Jun 30 '13 at 17:15
21

The version is declared in the web.xml file using the attribute version.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     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_2_5.xsd"
     version="2.5">
...
</web-app>

Read more

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
cljk
  • 936
  • 1
  • 7
  • 20