• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GenericServlet n Http Method....

 
Poonam Akash
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can we define a doGet(HttpServletRequest req,HttpServletResponse res)or doPost(..) in GenericServlet class to handle http requests.
i think its possible as i have read that GenericServlet is a servlet that can handle any type of request(ftp,http,etc.)
Any comment will be acknowledeged greatly.
Bye.

 
Tim Duncan
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Huh? are you suggesting editing the existing implementation of GenericServlet?
You can, of course subclass GenericServlet and have your class handle any request type that is dervied from ServletRequest. In fact that's just what HttpServlet does!
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by poonam :

Can we define a doGet(HttpServletRequest req,HttpServletResponse res)or doPost(..) in GenericServlet class to handle http requests.

Poonam yes u can as GenericServlet is protocol-independent, but no point to reinvent the wheel....
------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3820
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Theoretically Yes, but practically No. You cannot just subclass GenericServlet and implement doGet(...) to handle http get requests.
Ever wondered who calls doGet(...)? The service() method of HttpServlet. GenericServlet has no idea about GET/POST etc. HttpServlet overrides the service methods and "implements" the HTTP protocol to determine what kind of request is it and then calls the appropriate doXXX method. By implementing the HTTP protocol, I mean, it analyses the stream of characters/bits, breaks it into different components like HEADER, BODY, ATTACHMENTS etc. Are you willing to write all that code?
It's not trivial and that's the reason HttpServlet class is a standard class provided by Sun.

------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic