• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GenericServlet

 
thilak subbiah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServlet extends GenericServlet, so we can access all methods of GenericServlet from HttpServlet itself.So, by extending HttpServlet, can we write a GenericServlet?

------------------
 
Pranav Jaidka
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Thilak
there is a difference in the way the Servlet Engine handles the Generic servlet and the Http Servlet.
The Generic Servlet needs the service method to be overidden while the httpServlet needs the doGet or the doPost method to be overidden .The Calls to these are however routed through the Service method .
I cant understand why you need to do the thing you mentioned as you can see there is not much gained by trying to replicate the generic functionality in the httpServlet.
Thats why the HttpServlet was made
regards
pranav

 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You will have to subclass the GenericServlet class and provide implementation for the service() method. You might want to refer to the Sun Tutorial on Servlets and the Java servlet programming book for reference.
Ashwin.
 
MSD
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write a generic servlet by extending HttpServlet, though it doesn't make much sense.
The HttpServlet overrides the service() method of GenericServlet and reroutes the request to doGet() or doPost() method depending on the request type. So you can subclass the HttpServlet and override the service method to provide our own behaviour.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic