Q. What are Servlets?
A.
Servlets are small programs which execute on the web serverĀ  They run under web server environment exploiting the functionalities of the web server. The applets dynamically extend the functionality of a web browser,but the servlets dynamically extend the functionality of a web server.

Q. What is a Servlet Container?
A.
The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent,decodes MIME-based requests, and formats MIME-based responses.
A servlet container also contains and manages servlets through their lifecycle.

Q.List the uses of Servlet?
A.
Servlets are most often used to-
1.Process or store the data that was submitted from an HTML form.
2.Provide dynamic content such as the results of a database query.
3.Manage state information that does not exist in the stateless HTTP Protocol.

Q. What are the two important APIs for Servlets?
A.
The two important packages are required to build servlet”javax.servlet” and “javax.servlet.http”.They form the core of Servlet API.Servlets are not part of core java but are standard extensions provided by Tomcat.

Q. Compare the Servlets with other technologies?
A.
In functionality, servlets lie somewhere between Common Gateway Interface (CGI)programs and proprietary server extensions such as the Netscape Server API(NSAPI) or Apache Modules.
Servlets have the following advantages over other server extension mechanisms:
1.They are generally much faster than CGI scripts because a different process model is used.
2.They use a standard API that is supported by many Web servers.
3.They have all the advantages of the Java programming language, including ease of development and platform independence.
4.They can access the large set of APIs available for the java platform.

Q. Can servlet have a constructor?
A
. Yes,servlet have a constructor.

Q. How a Servlet is unloaded?
A.
A servlet is unloaded when-
1.Server shuts down.
2.Administrator manually unloads.

Q. What is pre-initialization of a Servlet?
A. Servlet initialization play a major & vital role in any web application based on java.
Web container does not design to load servlet by default, but container have feature for passing a parameter by <load-on-startup> tag using deployment descriptor (web.xml), if the parameter value 1 then servlet initialize after deployment of application(.war), in the case of value 2 servlet calls only, whenever application need, it is also known as lazy loading.

[code lang=”xml”] <load-on-startup>2</load-on-startup>[/code]

Q.What are the different ways to communicate between servlets?
A.The different ways to communicate between servlets are given below-
1.Using RequestDispatcher object.
2.Sharing resource using”ServletContext()” object.
3.Include response of the resource in the response of the servlet.
4.Calling public methods of the resource.
5.Servlet chaining.
Q. Name the annotations that are mostly used in Servlet 3?
A.The annotations that are mostly used in Servlet 3 are-
@WebServlet : for servlet class.
@WebListener: for listener class.
@WebFilter : for filter class.