Servlet HttpServlet

In this tutorial you will learn about the Servlet HttpServlet and its application with practical example.

Servlet HttpServlet Class

The HttpServlet class is a sub class of GenericServlet Class, It means it extends GenericServlet class and also it implements Serializable interface. It provides some specific methods like doGet, doPost, doHead, doTrace ,doDelete etc.

Table Of Contents

Syntax:-

HttpServlet Class Methods

public void service(ServletRequest req,ServletResponse res) :- This method used to dispatches client request to the protected service method.

protected void service(HttpServletRequest req, HttpServletResponse res):- This is method which receives standard HTTP from the public service method and dispatch them to the doXXX() methods(depends upon incoming http request).

3.protected void doGet(HttpServletRequest req, HttpServletResponse res):- This method called by the server(via service method) to allow a servlet to handle GET request.

4 protected void doPost(HttpServletRequest req, HttpServletResponse res):- This method called by the server(via service method) to allow a servlet to handle POST request.

protected void doHead(HttpServletRequest req, HttpServletResponse res):- This method receives an HTTP Head request from the protected service method and handle the request.

6.protected void doOptions(HttpServletRequest req, HttpServletResponse res):- This method called by the server(via service method) to allow a servlet to handle OPTIONS request.

7.protected void doPut(HttpServletRequest req, HttpServletResponse res) :- This method called by the server(via service method) to allow a servlet to handle PUT request.

8.protected void doTrace(HttpServletRequest req, HttpServletResponse res):- This method called by the server(via service method) to allow a servlet to handle TRACE request.

9.protected void doDelete(HttpServletRequest req, HttpServletResponse res):- This method called by the server(via service method) to allow a servlet to handle DELETE request.

10.protected long getLastModified(HttpServletRequest req):- This method returns the time the HttpServletRequest object was last modified.

In this tutorial we have learn about the Servlet HttpServlet and its application with practical example. I hope you will like this tutorial.