Servlets Java Interview Questions With Answers
Servlet Objective Questions And Answers
Servlet Objective Questions And Answers (NEW)
Servlet Subjective Questions And Answers
Servlet Subjective Questions And Answers (NEW)
Servlet Interview Questions And Answers
Servlet Interview Questions And Answers(NEW)
Servlets
Q: 1) What is the servlet?
Ans : Servlets are modules that extend request/response-oriented
servers, such as Java-enabled web servers. For example, a servlet might be
responsible for taking data in an HTML order-entry form and applying the
business logic used to update a company's order database.
Servlets are to servers what applets are to browsers. Unlike applets,
however, servlets have no graphical user interface.
Q: 2) Whats the advantages using servlets than using CGI?
Ans : Servlets provide a way to generate dynamic documents that is both
easier to write and faster to run. Servlets also address the problem of
doing server-side programming with platform-specific APIs: they are
developed with the Java Servlet API, a standard Java extension.
Q: 3) What are the uses of Servlets?
Ans : A servlet can handle multiple requests concurrently, and can
synchronize requests. This allows servlets to support systems such as
on-line conferencing.
Servlets can forward requests to other servers and servlets.Thus servlets
can be used to balance load among several servers that mirror the same
content, and to partition a single logical service over several servers,
according to task type or organizational boundaries.
Q: 4) Which pakage provides interfaces and classes for writing servlets?
Ans : javax
Q: 5) Whats the Servlet Interfcae?
Ans : The central abstraction in the Servlet API is the Servlet
interface. All servlets implement this interface, either directly or, more
commonly, by extending a class that implements it such as HttpServlet.
Servlets-->Generic Servlet-->HttpServlet-->MyServlet.
The Servlet interface declares, but does not implement, methods that
manage the servlet and its communications with clients. Servlet writers
provide some or all of these methods when developing a servlet.
Q: 6) When a servlet accepts a call from a client, it receives two objects-
What are they?
Ans : ServeltRequest: Which encapsulates the communication from the
client to the server. ServletResponse: Whcih encapsulates the
communication from the servlet back to the client. ServletRequest and
ServletResponse are interfaces defined by the javax.servlet package.
Q: 7) What information that the ServletRequest interface allows the servlet
access to?
Ans : Information such as the names of the parameters passed in by the
client, the protocol (scheme) being used by the client, and the names of
the remote host that made the request and the server that received it.
The input stream, ServletInputStream.Servlets use the input stream to get
data from clients that use application protocols such as the HTTP POST and
PUT methods.
Q: 8) What information that the ServletResponse interface gives the servlet
methods for replying to the client?
Ans : It Allows the servlet to set the content length and MIME type of
the reply.
Provides an output stream, ServletOutputStream and a Writer through which
the servlet can send the reply data.
Q: 9) What is the servlet Lifecycle?
Ans : Each servlet has the same life cycle:
A server loads and initializes the servlet (init())
The servlet handles zero or more client requests (service())
The server removes the servlet (destroy())
(some servers do this step only when they shut down)
Q: 10) How HTTP Servlet handles client requests?
Ans : An HTTP Servlet handles client requests through its service
method. The service method supports standard HTTP client requests by
dispatching each request to a method designed to handle that request.
Tolal:0 Click:
Show All Comments