Ad Home

Theme images by kelvinjay. Powered by Blogger.


Header Ads





General QA Concept


» » Servlet Architecture ::2 packaged architecture

If you are trying to create a servlet program of your own ,the two main class for servlet implementation are-

  1. GenericServlet---For all general purpose servlet capable of handling any protocol.
  2. HttpServlet-- HttpServlet is a extended class from GenericServlet , handles only HTTP protocol.
So when we try to create any of the servlet of our own ,we need to extend one of these classes.
P.S-Servlet does not contain any main() method instead it is having a service() method to work.
if you are extending GenericServlet:
public abstract void service(ServletRequest req,ServletResponse res) throws ServletException,IOException;
The two types of object a service method accepts are

  1. Request--the information directing to the servlet
  2. Response--The information towards server viz client 

if you are extending  HttpServlet :
well this is bit advanced process. when ever you are extending to HttpServlet, the service() method is written we need to invoke that method. HttpServlet.service().
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException

The best part of this when the service method is called,it determines the request and which methods to be called.Say we have the method type is GET then doGet() method is called or else if we have post as request method then corresponding doPost() method is called.
Note: All these methods can be overridden.
The other methods inside a HttpServlet's service method are-

  1. doDelete()
  2. doGet()
  3. doOption()
  4. doPost()
  5. doPut()
  6. doTrace()

Image source:

Newer Post
Older Post

No comments:

Leave a Reply