doGet()与doPost()区别

After the servlet is initialized, the container may keep it ready for handling client
requests. When client requests arrive, they are delegated to the servlet through the
service()method, passing the request and response objects as parameters. In the
case of HTTP requests, the request and response objects are implementations of
HttpServletRequest and HttpServletResponse respectively. In the
HttpServlet class, the service() method invokes a different handler method for
each type of HTTP request, doGet() method for GET requests, doPost() method for
POST requests, and so on.


some more,


GET method

The GET method is used to retrieve a resource (like an image or an HTML page) from
the server, which is specified in the request URL. When the user types the request
URL into the browser's location field or clicks on a hyperlink, the GET method is
triggered. If a tag is used, the method attribute can be specified as "GET" to cause the
browser to send a GET request. Even if no method attribute is specified, the browser
uses the GET method by default.
We can pass request parameters by having a query string appended to the request
URL, which is a set of name-value pairs separated by an "&" character. Here we have passed the parameters studname and studno, which have the values
"Tom" and "123" respectively. Because the data passed using the GET method is
visible inside the URL, it is not advisable to send sensitive information in this manner.
The other restrictions for the GET method are that it can pass only text data and not more than 255 characters (i read somewhere that it depends on browser support).


POST method
The purpose of the POST method is to "post" or send information to the server. It is
possible to send an unlimited amount of data as part of a POST request, and the type of
data can be binary or text.
This method is usually used for sending bulk data, such as uploading files or updating
databases. The method attribute of the <form> tag can be specified as "POST" to
cause the browser to send a POST request to the server.
Because the request parameters are sent as part of the request body, it is not visible
as part of the request URL, which was also the case with the GET method.

你可能感兴趣的:(html,servlet)