R4R Team working to provide free of cost for experienced and freshers

Tutorials | Examples|Interview Questions and Answers|Java Tutorials| C Tutorials | C++ Tutorials | Spring Tutorials| Hibernate Tutorials | JSP Tutorials | Servelets Tutorials| C# Tutorials | PHP Tutorials etc , Basics | Download Software | Data Types | Variables | Constant | Storage & Classes | Operators | Decisions Making | Loops | Functions| Numbers | Arrays | Pointers | String | Datastructure | Expressions | Preprocessor Statement | I/O | Exception Handling | OOPs Tutorial | Classes and object |C++ Inheritance Overloading | Polymorphism | Abstraction | Encapsulation | Interfaces | Multithreading etc

Java Servlet Programing Laungage

Java Servlet Projects

Servlet Project 3

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