Google News
logo
Java Servlets - Interview Questions
Explain the Servlet API.
A servlet does not have a main() method, unlike a regular Java program, and just like an applet. It has some methods of a servlet that are called upon by the server for the purpose of handling requests. It invokes the servlet’s service() method, every time the server sends a request to a servlet.
 
To handle requests that are appropriate for the servlet, a typical servlet must override its service() method. The service() method allows 2 parameters : these are the request object and the response object.

The request object is used to inform the servlet about the request, whereas the response object is used to then give a response.
 
As opposed to this, an HTTP servlet typically does not override the service() method. However, it actually overrides the doGet() to handle the GET requests and the doPost() to handle POST requests. Depending on the type of requests it needs to handle, an HTTP servlet can override either or both of these methods.
Advertisement