How to find JSP / Servlet / Java / App. Server Version using Code

The following line of codes will help you to get the following useful information

1. Application Server information  with version details
2. Servlet Version Information
3. JSP Version information
4. Java Version Information

For Servlet

If you are using Servlet, you can use following lines of code for displaying Server & Servlet Information

package javaonline;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * Servlet implementation class GetVersion
public class GetVersion extends HttpServlet {
	private static final long serialVersionUID = 1L;
     * @see HttpServlet#HttpServlet()
    public GetVersion() {
        // TODO Auto-generated constructor stub

	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    protected void doGet(HttpServletRequest requestObj, HttpServletResponse responseObj) 
    	       throws IOException 
    	  String serverInfo=requestObj.getSession().getServletContext().getServerInfo();
    	  System.out.println("Server Info" + serverInfo);
    	  String servletInfo= requestObj.getSession().getServletContext().getMajorVersion() + "." +  requestObj.getSession().getServletContext().getMinorVersion();
    	  System.out.println("Servlet Info" + servletInfo);



If you are using JSP , the following line of codes will help you to get Application Server Info, Servlet and JSP version info.

Here we are using the implicit objects session & application to get the information.

1) To get the Application Server Information, use the following lines of code

 <%= application.getServerInfo() %>


2) To get the Servlet Information(Version Info), use the following lines of code

<%= session.getServletContext().getMajorVersion() %>.<%= session.getServletContext().getMinorVersion() %>
 <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %>


3) To get the JSP Information(Version Info), use the following line of code

<%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %>


4) To get the Java Version Info, use the following line of code

<%= System.getProperty(“java.version”)

Leave a Reply