Thursday, 1 March 2012
J2EE: SERVLET: Class GenericServlet vs Class HttpServlet
Do you like this Article?
· It is an abstract class which defines a generic and protocol independent servlet. Here, protocol independent means, by default, it doesn’t contain inherent support for any particular type of protocol, but it can be extended to provide implementation of any protocol.
· Class GenericServlet implements Interface Servlet and Interface ServletConfig and it belongs to javax.servlet package.
· It offers simpler version of the servlet life cycle methods init() and destroy() and the methods of ServletConfig. That’s why, it makes writing a servlet easier.
· Here, the method service(ServletRequest req, ServletResponse res) is abstract, so the subclasses must override it. And this is also the reason why the GenericServlet is an abstract class.
· It is also an abstract class which defines HTTP prototype dependent servlet. That means we need to extend it to write a HTTP servlet for the use of the web.
· Class HttpServlet is a subclass of Class GenericServlet and it belongs to javax.servlet.http package.
· As it’s an abstract class, a subclass of it must override at least 1 method, generally one of these doGet(), doPost(), doPut(), doDelete(), init(), destroy(), getServletInfo().
· Class HttpServlet has two service() methods - one is public void service(ServletRequest req, ServletResponse res) which dispatches client request to protected void service(ServletRequest req, ServletResponse resp) which again dispaches the request to the doXXX methods (like doGet(), doPost(), etc.).
Anijit Sarkar
Subscribe to:
Post Comments
(
Atom
)
Popular Posts
-
public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [ Java Virtual Machine...
-
throw is used to throw an exception in a program, explicitly . Whereas, throws is included in the method's declaration part, wi...
-
Singleton in one of the most popular yet controversial design pattern, in the world of object oriented programming. It's one of t...
-
Web Container / Servlet Container / Servlet Engine : In J2EE Architecture , a web container (also known as servlet container or ser...
-
Program compiles. But at runtime throws an error “NoSuchMethodError”.
-
Vector : It's synchronized. It's slower than ArrayList. It's generally used in ...
-
doGet(): protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException – is a met...
-
In Java Programming Language , we must declare a variable name and type, before using it. The data type of a variable defines the th...
3 Responses to “ J2EE: SERVLET: Class GenericServlet vs Class HttpServlet ”
20 August 2012 at 13:14
the prototype of service() method is wrong.
correct one is public void service(ServletRequest req,ServletResponse req) and
protected void service(HttpServletRequset req,HttpServletResponse res)....
28 October 2012 at 17:14
Nice post . . Very Useful information
Dhung.com provid interview question and answer for all company.
10 March 2018 at 16:24 This comment has been removed by the author.
Post a Comment