How to find servlet version for Glassfish server?

When coding a servlet, I found a method that says

Since: Servlet 3.1 

I assume that if I have autohint from NetBeans to use it, it is because I have this version of the servlet. But I can’t find a place to confirm this. I use glassfish4.1 as a container. If I go to mypathtoglassfish4.1\glassfish\modules , there I will see javax.servlet-api.jar and inside the manifest, which says:

 Implementation-Version: 3.1.0 

Is this the right way to test this? I am particularly interested in telling my colleagues to "go to this bank and check this property," so I am sure that my code will work on their server.

As an alternative, I found the Oracle GlassFish Server 3.1 web page Application Development Guide , which states: "GlassFish Server supports Java Servlet Version 3.0." but obviously for Glassfish 3.1, and I could not find any of them for each version of glass fish (not even mine -4.1).

+1
source share
2 answers

Check out the Java EE version . Servlet version (JSP, JSF, EJB, JPA, etc.) Goes hand in hand with the 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 homepage / documentation on the server how it presents itself. For GlassFish , which is currently (since 4.1):

The world's first Java EE 7 application server

So this is Servlet 3.1.

But with a big one , but , this is one thing. Secondly, the webapp version web.xml also plays a role. Not everyone knows that.

If your webapp web.xml declared compliant with servlet 3.1, as shown 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 work in Servlet 3.1 module.

However, if he announced that Servlet 3.0 is lower 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 work in the Servlet 3.0 compatibility module, even if it is deployed in a container compatible with Servlet 3.1! The above affects ServletContext#getMajorVersion() and getMinorVersion() , so they actually don't say anything about the container, but only about the web server itself.

If your webapp web.xml contains <!DOCTYPE> , regardless of DTD and version, then it will work in the Servlet 2.3 compatibility module, even if a new XSD is announced!

 <?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> 
+5
source

First, see GlassFish Open Source Version Comparison Versions 2.x and 3.0.x. Also in your servlet you can add

 HttpSession session = request.getSession(); int majorVersion = session.getServletContext().getMajorVersion(); int minorVersion = session.getServletContext().getMinorVersion(); 
0
source

Source: https://habr.com/ru/post/1273777/


All Articles