Java Servlets Question and Answers

13. What are the methods of HttpServlet?
  The methods of HttpServlet class are
  • doGet() is used to handle the GET, conditional GET, and HEAD requests
  • doPost() is used to handle POST requests
  • doPut() is used to handle PUT requests
  • doDelete() is used to handle DELETE requests
  • doOptions() is used to handle the OPTIONS requests and
  • doTrace() is used to handle the TRACE requests.
 
Your Name Your Email-ID
Your Answer
14. What are the differences between HttpServlet and GenericServlets?
 
  • HttpServlet provides an abstract class to be subclassed to create an HTTP servlet suitable for a website. A subclass of HttpServlet must override at least one method, usually one of these:
  • doGet, if the servlet supports HTTP GET requests
  • doPost, for HTTP POST requests
  • doPut, for HTTP PUT requests
  • doDelete, for HTTP DELETE requests
  • init and destroy, to manage resources that are held for the life of the servlet
  • getServletInfo, which the servlet uses to provide information about itself.
  • There's almost no reason to override the service method. Service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above). Likewise, there's almost no reason to override the doOptions and doTrace methods.
  • GenericServlet: defines a generic, protocol independent servlet. To write an HTTP servlet for use on the web, extend HttpServlet instead.
  • GenericServlet implements the Servlet and ServletConfig interfaces. GenericServlet may be directly extended by a servlet, although it's more common to extend a protocol specific subclass such as HttpServlet.
  • GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface. To write a generic servlet, you need to only override the abstract service method.
 
Your Name Your Email-ID
Your Answer
15. What mechanisms are used by a Servlet Container to maintain Session Information?
  Servlet Container uses Cookies, URL rewriting and HTTPS protocol information to maintain the session.
 
Your Name Your Email-ID
Your Answer
16. What are the type of protocols supported by HTTPServlet?
  It extends the GenericServlet base class and provides a framework for handling the HTTP protocol. So, HTTPServlet only supports HTTP and HTTPS protocol.
 
Your Name Your Email-ID
Your Answer
1234567891011 Page 4 of 11