What is servlet hierarchy I GenericServlet?
The GenericServlet class of the Servlet API implements the Servlet interface. In addition to the Servlet interface, the GenericServlet class implements the ServletConfig interface of the Servlet API and the Serializable interface of the standard java.io. package.
What is difference between HttpServlet and GenericServlet?
The main difference between GenericServlet and HttpServlet is that the GenericServlet is protocol independent that can be used with any protocol such as HTTP, SMTP, FTP, CGI etc. while HttpServlet is protocol dependent and is only used with HTTP protocol.
Which package does GenericServlet belong?
javax.servlet
Figure 25-1. The javax. servlet package
GenericServlet | Servlets 1.0 |
---|---|
javax.servlet | serializable |
What is GenericServlet in Java?
Defines a generic, protocol-independent servlet. 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.
What is the purpose of RequestDispatcher object?
The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name. This interface is intended to wrap servlets, but a servlet container can create RequestDispatcher objects to wrap any type of resource.
What is the purpose of RequestDispatcher interface?
The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.
Why GenericServlet is an abstract class?
GenericServlet is an abstract class and it has only one abstract method, which is service(). That’s why when we create Generic Servlet by extending GenericServlet class, we must override service() method. 3. To write Generic Servlet you just need to extend javax.
Why we use HttpServlet instead of GenericServlet?
HttpServlet defines a HTTP protocol specific servlet. HttpServlet gives a blueprint for Http servlet and makes writing them easier. HttpServlet extends the GenericServlet and hence inherits the properties GenericServlet.
Is GenericServlet an abstract class?
GenericServlet is an abstract class and it has only one abstract method, which is service(). That’s why when we create Generic Servlet by extending GenericServlet class, we must override service() method.
What are the methods available in GenericServlet class?
Methods of GenericServlet class:
- init(ServletConfig config): It is used to initialize the servlet.
- service(ServletRequest request,ServletResponse response): It is used to respond to a request.
- destroy(): It is used to destroy the servlet.
- getServletConfig(): It returns a servlet config object.
Is GenericServlet an interface?
The GenericServlet class implements the Servlet interface and, for convenience, the ServletConfig interface. The GenericServlet class was created to make writing servlets easier. It provides simple versions of the life-cycle methods init and destroy, and of the methods in the ServletConfig interface.
What is the concept of RequestDispatcher?
javax.servlet public interface RequestDispatcher. Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server.
What is the class hierarchy of servlet?
Servlet Class Hierarchy. The Servlet interface is the root interface of the servlet class hierarchy. All Servlets need to either directly or indirectly implement the Servlet interface. The GenericServlet class of the Servlet API implements the Servlet interface.
What is GenericServlet class in servlet?
GenericServlet class implements Servlet, ServletConfig and Serializable interfaces. It provides the implementation of all the methods of these interfaces except the service method. GenericServlet class can handle any type of request so it is protocol-independent.
Why we must override service () method in generic servlet?
That’s why when we create Generic Servlet by extending GenericServlet class, we must override service () method. 1. Generic Servlet is easier to write
What is the HttpServlet class?
The HttpServlet class extends the GenericServlet class and provides built-in HTTP functionality. The servlet interface of the javax.servlet package defines methods that the Web container calls to manage the servlet life cycle. The following table describes various methods of the javax.servlet.Servlet interface: