Monday, March 17, 2008

Servlet basics

when we consider about the basics of a servlet we have to find the origin of it.
the Servlet interface comes here.which is javax.servlet.Servelt.we have some usefull method definitions there.some of them are
  • service(ServletRequest, ServletResponse)
  • init(ServletConfig)
  • destroy()
after that we meet the abstract class GenericServlet (javax.servlet.GenericServlet) which implements the servlet interface.so this class consists of its own methods + the methods come from the servlet interface.some usefull methods are
  • getInitParameter()
  • getInitParameterNames()
then we meet the abstract class HttpServlet (javax.servlet.http.HttpServlet) which extends the GenericServlet class.so this class consist of all the methods form the Servlet interface + Generic servlet class + its own methods.some of the usefull methods are
  • service(HttpServletRequest,HttpServletResponse)
  • doGet(HttpServletRequest,HttpServletResponse)
  • doPost(HttpServletRequest,HttpServletResponse
so when we write a servlet class we extend the HttpServlet class.(most often).we most often override the doGet() and doPost() methods.we define the business logic what ever we want inside them.

servlet config and servlet context
the ServletConfig object contain the deploy time information of a servlet and the ServletContext will be accessed through this object.and per servlet there will be only one ServletConfig object.the servletContext is used to access web application parameters.and per web application there will be one ServletContext.

the doGet() and the doPost()
post is more secured and it has a body where the get does not have.we can use a limited number of parameters with the get.post cannot be bookmarked and is used to send data to process.get is used to get some resourse.

1 comment:

Anonymous said...

Hello Machn I'm Sandaruwan From Wadduwa. I'm a BIT student.
Here's my blog.

AgroSphere

I'm also an Adsense publisher like you. How is your cmpagn going on.