Request and response

Source: Internet
Author: User

Request object: provides all the information provided by the client when the client requests a page or passes a form. This includes

Indicates the HTTP variable of the browser and the user, and stores the cookie in the browser under this domain name.

The value of the HTML control in the <form> segment of the string or page appended to the URL. Also available

Authorized access to the Secure Socket Layer (SSL) or other encrypted communication protocols and to facilitate connection management

Attribute.


Response object: used to access the response information created by the server and returned to the client concurrently. Provide HTTP variables for the script to specify the server

Functions of the server and server, information about the content sent back to the browser, and any information that will be stored in the browser for this domain

New cookie. It also provides a series of methods to create output, such as the ubiquitous response. Write

Method.


COOKIE: cookies are a very small text file placed on your hard disk by the Web server when you browse a website. They can be recorded

Your User ID, password, browsed web page, stay time, and other information. When you come to this website again, the website reads

Cookies: when you know your information, you can make corresponding actions, such as displaying your welcome slogans on the page or

Enter the ID and password to log on directly.


The general point is:


Request: it can be understood as the information requested by the client to the server, that is, when the client requests to the server

Your browser information, HTTP variables, and cookies that are stored on the client are sent to the server, so that the server can judge based on the information.

Who requested it? Have you ever requested it before? What is the Session of the corresponding client.


Response: It can be understood as the server's response to the client request, that is, after the server receives the request from the client, generate page information, cookies (stored on the client after being sent to the client), and send them to the client.


After understanding their differences, let's talk about their respective usage methods.


Request usage:


There are three ways to get the form value for a request, which are used for obtaining different form submission methods. A form can be considered as a page

A set of parameters to be passed, and the submitted methods include two post and get. In

The two methods correspond to different receiving methods respectively. The specific implementation is as follows:


1. For the method for obtaining the value of the form submitted by the POST method, use the get method of the form attribute of the request to obtain the ID of the desired field. For example, the following code is used to obtain the TXT username value in the submission form and put it in the string usrname,

String username = request. Form. Get ("txtusername"). tostring ();


2. Use the field identifier in the querystring attribute of the request to obtain the value of the form submitted by the get method. For example, the following code obtains the TXT username value in the submission form and places it in the usrname string,

String username = request. querystring ["txtusername"]. tostring ();


3. For both methods, use the index value of the request to obtain the value in the form. The Code is as follows,

String username = request ["txtusername"]. tostring ();

Response usage:


The main methods used here are response. Write (string) and response. Redirect (URL ).


Response. Write (string) is used to return data (write data) from the server to the client)

Response. redirec ("url") is used to redirect to another webpage on the server side.


These things are often used when writing code. Although they look a little similar, they are very different and have almost the opposite effect. I hope you don't confuse them with the opposite.


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.