Getting Servlet Version Info 

A program (servlet or JSP) may want to know the version what version of  the Servlet API is current.

Here is a simple JSP that shows this information.

 The the version of Servlets currently running is:
<%
int majorVersion = application.getMajorVersion();
int minorVersion = application.getMinorVersion();
out.println(majorVersion + "." + minorVersion);
%>


Here is a Servlet that does the same thing:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowJrun extends HttpServlet {
PrintWriter out = null;
public void service (ServletRequest req , ServletResponse res) throws IOException {
try {
res.setContentType("text/html");
out = res.getWriter();
 ServletContext sc = getServletContext();
 int majorVersion = sc.getMajorVersion();
int minorVersion = sc.getMinorVersion();
out.println("The Servlet version is " + majorVersion + "." + minorVersion + "<BR>");

}catch (Exception e) {
out.println("Exception " + e);
}
}
}