The difference between post and get

Source: Internet
Author: User
Tags commit html header http post port number server port
1. Get is the data that is fetched from the server and post is the data sent to the server.
2. Get is the URL where the parameter data queue is added to the Action property of the submission form, and the value corresponds to the field one by one in the form, which is visible in the URL. Post is the HTTP post mechanism that places the fields within the form with their contents in the HTML header, along with the URL address referred to by the Action property. The user does not see the process.
3. For Get mode, the server side uses Request.QueryString to get the value of the variable, and for post, the server side uses Request.Form to obtain the submitted data.
4. Get transmits a small amount of data, cannot be greater than 2KB. Post transmits a large amount of data, which is generally not restricted by default. In theory, however, the maximum amount of IIS4 is 100KB in 80KB,IIS5.
5. Get security is very low, post security is high. But the execution efficiency is better than the Post method. 

Recommendation:
1, get the security of the method than the Post method to be less, including confidential information, it is recommended to use Post data submission method;
2, in the data query, it is recommended to use the Get method, and in the data to add, modify or delete, the proposed post method;

Under what circumstances is a get commit, and in what case is it a post submission?

Get commit:

1), the default form submission method

2), submit data with "<A>" link

3), append data directly to the URL of the address bar

"Eg:http://localhost:8080/project/index.jsp?id=1&name=admin"

Post submission:

1), the method for displaying the specified form is post, and the vast majority of forms are submitted by post.

second, JSP built-in objects

2.1 Out Object

Out: Outputs (prints) data to the client (or IE).

Common methods:

OUT.PRINTLN ("server-side output information sent to the client (IE)");

Out.write ("Same");

2.2 Request Object

Request function: is to interact with the client, collect the client's form, Cookies, hyperlinks, or collect server-side environment variables, in the program to obtain any information about the client must pass the request implicit object.

Common methods:

Request.getparameter ("name"): Gets the value of a form element, returned as a string, and returns null if the parameter name is wrong or has no corresponding parameter.

Request.getparametervalues ("name"): Gets multiple values of the form element with the same name, returned as an array of strings, or null if the parameter name is wrong or has no corresponding parameter.

Request.setcharacterencoding ("GBK"): Set request encoding format

http://localhost:8080/t4/demo1.jsp

Request.getscheme (): Get Transfer Protocol

Request.getservername (): Get server name

Request.getserverport (): Get Server port number

Request.getcontextpath (): Get Application Context Path

Request.setattribute (): Submit property value to request

Request.getattribute (): Get the property value in the request

2.3 Response Object

Response: Encapsulates the server's response to the client's data, in which the server aspires to the client response data must pass the response implicit object.

Common methods:

Response.sendredirect (): redirect

third, request processing

3.1 Get request parameter values

Common methods for using request:

String s=request.getparament ("Stu");//Get A

String[] S=request.getparament ("Stu");//Get multiple

3.2 Request parameter encoding format conversion

POST request:

Request.setcharacterencoding ("GBK");

String s=request.getparament ("Stu");

GET Request:

String s=request.getparament ("Stu");

String Str=new string (s.getbytes ("iso8859-1"), "GBK");

Four, page jump

4.1 Forwarding

Request.getrequestdispatcher (""). Forward (Request,response);

4.2 Redirects

Response.sendredirect ()

4.3 differences

1), the Address bar URL is not changed when forwarding, redirect will change

2), shared requests and responses when forwarding, redirection not shared

3), when forwarding the property value can be submitted to the request, the forwarded page can be accessed to

The property value that was just added, redirection cannot be accessed

    4), forwarding is limited to the current application, redirect can be targeted to any URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.