Reputation: 984
In java servlet, whenever we create Servlet class by extending the GenericServlet class then session management is not possible.
So I am interested to know the same
Upvotes: 1
Views: 276
Reputation: 2014
There are no protocol-specific features in GenericServlet, which is an implementation of the basic, general purpose Servlet interface. Servlet-based Sessions are designed only for interactions using the HTTP protocol, which has two key features necessary for a Servlet Container to simulate continuous user Sessions: cookies and URL-based navigation, which supports URL-rewriting. The Servlet API therefore places the HttpSession interface in the javax.servlet.http package, and Session references are only available through classes in this package
So,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. You may create a generic servlet by inheriting the GenericServlet class and providing the implementation of the service method.
Upvotes: 0
Reputation: 21
HTTP Session is a HTTP specific thing. The generic Servlet has no idea of HTTP concepts, only the HTTPServlet does.
As to your next question: "When do you need GenericServlet?" the answer is never.
Upvotes: 2