Books of every technology is available for free in this site in pdf format.
www.flazx.com
Monday, September 21, 2009
Tuesday, September 8, 2009
Servlet and Jsp Version and Server Information
Servlet and Jsp Version and also the Server information such as name and version that is being used can be obtained using the follwing code.
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
public class VersionServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
//Servlet Version
//getMajorVersion() -> Returns the major version of the Java Servlet API that this servlet container supports.
//getMinorVersion() -> Returns the minor version of the Servlet API that this servlet container supports.
out.println("Servlet Version " +
this.getServletContext().getMajorVersion() + "." +
this.getServletContext().getMinorVersion());
//Jsp Version
out.println("Jsp Version " +
JspFactory.getDefaultFactory().getEngineInfo().
getSpecificationVersion());
//ServerInformation
//getServerInfo -> Returns the name and version of the servlet container on which the servlet is running.
out.println("Server Info " + this.getServletContext().getServerInfo());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspFactory;
public class VersionServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
//Servlet Version
//getMajorVersion() -> Returns the major version of the Java Servlet API that this servlet container supports.
//getMinorVersion() -> Returns the minor version of the Servlet API that this servlet container supports.
out.println("Servlet Version " +
this.getServletContext().getMajorVersion() + "." +
this.getServletContext().getMinorVersion());
//Jsp Version
out.println("Jsp Version " +
JspFactory.getDefaultFactory().getEngineInfo().
getSpecificationVersion());
//ServerInformation
//getServerInfo -> Returns the name and version of the servlet container on which the servlet is running.
out.println("Server Info " + this.getServletContext().getServerInfo());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Subscribe to:
Posts (Atom)