Answer: 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.
Answer: 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.
Answer: 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.
Answer: 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.
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?
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?
Answer: 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?
Answer: It Allows the servlet to set the content length and MIME type of the reply.
Answer: 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)
Answer: 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.