Sunday, November 28, 2010

Servlets

Question : What is Servlet?
Definition 1: A small Java program that runs within a web server.servlets
 receive and response to the request from the Web Clients usually across HTTP.
              2) It runs completely inside the JVM.
Definition 2: A servlet is a java class therefore needs to be executed inside
 the JVM, by a service we called Servlet engine.


Question: What is JSDK?
Answer: All servlets API classes and Simple servlet enables web server are 
combined into Java Servlet Development Kit(JSDK).

Question :What are life cycle methods of the servlet interface?
Ans: The interface servlet defines the methods for the servlet life cycle. those are
         1) init Method() :  servlet constructed and initialized
         2) service method() : calls from clients are handled here.
         3) destroy method() :  servlet is taken out of service and destroyed.

Question : Who calls the service() method ?
Ans: called by the servlet container to allow the servlet to handle the request.

Explain the Hierarchal of the servlets ?
Answer :   Servlet [ interface
            |   implements
GenericServlet [ abstract Class ]
           | extends
 HttpServlet   [ Abstract Class ]
          |
          ---------> implements [ serializable ]
          ---------> implements [ servlet ]
         ----------> implements [ ServletConfig ]
Question : What is servlet Config?
Ans : It is an interface, used by the servlet container used to pass information to 
servlet during initialization.

Question : What is servletContext ?
Ans : It is an Interface, used by the servlet to communicate with the servlet container
to get the information such as MIME type of a file , write to a log file.

Note: ServletContext is the object contained within the servletConfig object, where this
 object is passed to the servlet by the servlet container during servlet initialization.


Note: There is only one context with the one web application or with one JVM.


Question : advantages of servlets over the CGI?
Answer : Platform Independent : because servlets written in java language.
              Performance: CGI creates a new process to handle a new request,Servlet creates a new thread.

No comments:

AWS certification question

AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...