World's most popular travel blog for travel bloggers.

Ques : GET and POST Methods

, , No Comments

 The GET methods is a request made by browsers when the user types in a URL on the

address line, follows a link from a Web page, or makes an HTML form that does not
specify a METHOD. Servlets can also very easily handle POST requests, which are
generated when someone creates an HTML form that specifies METHOD="POST".

The program code given below will give you some idea to write a servlet program:

import java.io*;

import javax.servlet.;

import javax.servlet.http.*;

public class SomeServlet extends HttpServlet

{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException

{

// Use "request" to read incoming HTTP headers (e.g. cookies)
// and HTML form data (e.g. data the user entered and submitted)

// Use "response" to specify the HTTP response line and headers
// (e.g. specifying the content type, setting cookies).
PrintWriter out = response.getWriter();
// Use "out" to send content to browser

}
}

To act as a servlet, a class should extend HttpServlet and override doGet or doPost (or
both), depending on whether the data is being sent by GET or by POST. These
methods take two arguments: an HttpServletRequest and an HttpServletResponse
objects.
The HttpServletRequest has methods for information about incoming information
such as FORM data, HTTP request headers etc.
The httpServletResponse has methods that let you specify the HTTP response line
(200, 404, etc.), response headers (Content-Type, Set-Cookie, etc.), and, most
importantly, a PrintWriter used to send output back to the 

0 comments:

Post a Comment

Let us know your responses and feedback