You are here:   HomeJava Servletintroduction to ServletTypes of Servlets
by Dinesh Thakur Category: introduction to Servlet

HttpServlet is an abstract class given under the servlet-api present. It is present in javax.servlet.http package and has no abstract methods. It extends GenericServlet class.

When the servlet container uses HTTP protocol to send request, then it creates HttpServletRequest and HttpServletResponse objects. HttpServletRequest binds the request information like header and request methods and HttpServletResponse binds all information of HTTP protocol.

HttpServlet does not override in it or destroy method. However, it uses service (-,-) method. ServletRequest and ServletResponse references are cast into HttpServletRequest and HttpServletResponse, respectively.

Methods in HttpServlet

The methods in httpservlet are given as follows:

i. protected void doDelete (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method) to allow a servlet to handle a DELETE request. The DELETE operation allows a client to remove a document or web page from the server.

ii. protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method)"to allow a servlet to handle a GET request. Overriding this method to support a GETrequest also automatically supports an HTTP HEAD request.

iii. protected void doHead(HttpServletRequest req,HttpServletResponse resp)

throws ServletException, IOException

Receives an HTTP HEAD request from the protected service method and handles the request.

iv. protected void doOptions(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method) to allow a servlet to handle OPTIONS request. The OPTIONS request determines which HTTP methods the server supports and returns an appropriate header.

v. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method) to allow a servlet to handle a POST request. The HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is useful when posting information such as credit card numbers.

vi. protected void doPut(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method) to allow a servlet to handle a PUT request. The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.

vii.· protected void doTrace(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException

Called by the server (via the service method) to allow a servlet to handle a TRACE request. ATRACE returns the headers sent with the TRACE request to the client, so that they can be used in debugging. There's no need to override this method.

viii. protected long getLastModified(HttpServletRequest req)

Returns the time the HttpServletRequest object was last modified, in milliseconds since midnight 1January 1970GMT.If the time is unknown, this method returns a negative number (the default).

ix. protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP· specific version of the service method. There's no need to override this method.

x. public void service (ServletRequest req/ ServletRespon,se res) throws ServletException, IOException

Dispatches client request to the protected service method. There's no need to override this method.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us