Java Servlet Programing Laungage

Java Servlet Projects

Servlet Project 3

adplus-dvertising
Java Servlet :HttpServlet class in Servlet and its implementation.
Previous Home Next

javax.servlet.http.HttpServlet

This class extends GenericServlet and defines method for each Http request.Commonly used methods of this class are doGet() and doPost() which are used to process http get and post request respectively.

Syntax
  1. public void doGet(HttpservletRequest request,HttpServletResponse response)	
    					throws ServletException,IOException ;
    	

    Parameters

    • response HttpServletResponse that encapsulates the response from the servlet.
    • request HttpServletRequest that encapsulates the request to the servlet.
    • Throws: IOException if detected when handling the request.
    • Throws: ServletException if the request could not be handled.
  2. public void doPost(HttpServletRequest request,HttpServletResponse response) 
    					throws ServletException,IOException;
    	

    Parameters

    • response HttpServletResponse that encapsulates the response from the servlet.
    • request HttpServletRequest that encapsulates the request to the servlet.
    • Throws: IOException if detected when handling the request.
    • Throws: ServletException if the request could not be handled.
Implementation of Httpservlet:-
public class HttpServlet extends GenericServlet
{
public void service(ServiceRequest request,ServiceResponse response) 
			throws ServletException,IOException
{
HttpServletRequest req=(HttpServletRequest)request ;
HttpServletResponse res=(HttpServletResponse)response ;
service(req,res);
}
protected void service(HttpServletRequest request,HttpServletResponse response) 
	throws ServletException,IOException
{
request type is checked and doGet() and doPost() etc methods are invoked.
}
public void doGet(HttpServletRequest request,HttpServletResponse response) 
			throws ServletException,IOException{}
public void doPost(HttpServletRequest request,HttpServletResponse response) 
			throws ServletException,IOException{}
}
Previous Home Next