difference in ServletRequest.getRequestDispather() and ServletContext.getRequestDispatcher() in Servlet

What is difference in ServletRequest.getRequestDispather() and ServletContext.getRequestDispatcher() in Servlet

Servletrequest.getRequestDispatcher(“url”) means the dispatch is relative to the current HTTP request.
Example code:

 
RequestDispatcher reqDispObj = request.getRequestDispatcher("/login.jsp");

getServletContext().getRequestDispatcher(“url”) means the dispatch is relative to the root of the ServletContext.
Example code:

RequestDispatcher reqDispObj = getServletContext().getRequestDispatcher("/testApp/login.jsp");

Difference between servletContext and ServletConfig

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on Difference between servletContext and ServletConfig

What is difference between servletContext and ServletConfig?

ServletConfig
ServletConfig is implemented by the servlet container to initialize a single servlet using init().  you can pass initialization parameters to the servlet using the web.xml deployment descriptor. Every servlet has its own ServletConfig object.

Continue reading “Difference between servletContext and ServletConfig”

What is preinitialization of servlet

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on What is preinitialization of servlet

What is preinitialization of servlet

In the java servlet life cycle, the first phase is called “Creation and intialization“.

The java servlet container first creates the servlet instance and then executes the init() method. This initialization can be done in Two ways. The default way is that, the java servlet is initialized when the servlet is called for the first time. This type of servlet initialization is called lazy loading.

Continue reading “What is preinitialization of servlet”

Setting Session Timeout in JSP Servlet

Author posted by Jitendra on Posted on under category Categories JSP, Servlet and tagged as Tags with Leave a comment on Setting Session Timeout in JSP Servlet

How to set the Session Time out in JSP and Servlet

Session can die in following three ways in J2EE application:

  1. Its Time out
  2. invalidate() method called on Session Object
  3. Application goes down (Application crashes or undeployed)

Continue reading “Setting Session Timeout in JSP Servlet”

Difference in HttpServlet and GenericServlet

Author posted by Jitendra on Posted on under category Categories JAVA, Servlet and tagged as Tags with Leave a comment on Difference in HttpServlet and GenericServlet

What is the basic Difference in HttpServlet and GenericServlet

javax.servlet.GenericServlet

Signature:

public abstract class GenericServlet extends java.lang.Object implements Servlet, ServletConfig, java.io.Serializable
  1. GenericServlet defines a generic, protocol-independent servlet.
  2. GenericServlet gives a blueprint and makes writing servlet easier.
  3. GenericServlet provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface.
  4. To write a generic servlet, it is sufficient to override the abstract service method.

Continue reading “Difference in HttpServlet and GenericServlet”