[Java] Get with post, client jump with server-side jump

Source: Internet
Author: User

http://www.thinksaas.cn/group/topic/133101/

Although get and post problems are very old, but as a web developer for this understanding is really necessary, in fact, when it comes to get and post, there can be doget and dopost and the client jump and the service side jump difference;

The difference between GET and post:

First, get is to obtain data from the server, Post is to send data to the server;

Second, get the data in the form in the form of variable=value, add to the URL address that the action points to after, and both with "?" connection, and each variable using the "&" connection. Post is to put the data in the form in the body of the form (or put the content in the HTTP message body), in accordance with the variables and values corresponding to the way the action is directed to the URL;

So we can get two other conclusions from the 2nd:

1, Get the amount of data transmitted less than 2KB, which is mainly due to the URL length limit.

Post transmits a large amount of data, so the upload file can only use post (note that in the file upload also add enctype= "Multipart/form-data" as the identity of the uploaded file). is generally not restricted by default. But theoretically, the maximum amount of IIS4 is 80KB, and the IIS5 is 100KB;

2, Get security is very low (because users can see through the URL)

Post Security is high (all of its operations are not visible to the user). But the execution efficiency is higher than the POST method (the advantage makes its disadvantage);

Summarize:

A, if it contains confidential information, it is recommended to use the Post data submission method;

b, when the data processing does not change the state of the model is recommended to use the Get method, such as doing data query. When the operation changes the state of the data model, it is recommended to use post methods, such as data addition, modification or deletion, sending email, etc.

The get limit of the data set of form form must be ASCII character, and Post supports the whole ISO10646 character set, so when there are some garbled characters, we can change the GET request to post request.

Four, Get is the default method of form;

The data submitted by the Get method is obtained by using request.querystring () on the server side, and the data submitted by post is obtained by Request.Form ().

Server-side jump with client-side jump:

First we need to understand what is the server-side jump and what is the client's jump. A simple understanding of the so-called server-side jump refers to the address bar content is unchanged (the client browser's address bar does not display the URL of the destination address), and the client jump refers to the address bar content changes (the client sends a request to the server, and then the server to the client a response, The client then sends the request to the server based on the URL in the server-side response, so it is two requests, so the address bar changes to show the last request address);

Server-side jump in Java:

1, Request.getrequestdispatcher ("success.jsp"). Forward (Request,response), it is a jump immediately after executing to this statement, you can pass the request property;

2, <jsp:forward>, this jump belongs to unconditional jump, it can only in the stack inward, and sendredirect can be arbitrary, or even input Baidu;

Client Jump:

1, Response.sendredirect ("fail.jsp"), all pages after the execution of the jump, cannot pass the properties of the request scope, but can be overridden by address to the jump page to pass parameters, because the method after the execution of the equivalent of an HTTP The end of the request, which is the server sends a 302 status code and a new URL to the client, tells the client to resend the request to the new URL, and then the client executes as a new request-response process begins. The server then re-creates the HttpServletRequest object and the HttpServletResponse object, at which point the two requests are no longer one thread, so the request and the response object are not the beginning;

2, Response.setheader ("Refresh", "2; Url=index.jsp "), 2 seconds after the jump to another page;

3, <a href= "http://www.baidu.com" > Baidu </a>, Hyperlink;

4. form submission;

As you can tell, if JDBC is used in a page now, you should close the database link before forward jump, and use respose to close at any location;

Attention:

1, the client Jump "/" on behalf of the server path WebApps, that is, the server root path, server-side Jump "/" represents the site root path, that is, the application root path;

2, try to use Response.sendredirect ("fail.jsp") instead of using forward, because when the server crashes, then Sendredirect will have a great advantage.

[Java] Get with post, client jump with server-side jump

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.