Introduction to ASP (eight)-request object small case

Source: Internet
Author: User
Tags send cookies servervariables

We will make a page that remembers the visitor's name, and in this small case you will learn how to use the values of the Request object's cookies, form, and ServerVariables collection, and learn how to use the Response object to send cookies.

First take a look at the program code:

<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%><!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><title>Remembering visitors ' names with cookies</title></Head><Body><%DimSusernamesusername= Trim(Request.Cookies ("name"))'To determine if name is empty and not NULL to output the value of nameIfsUserName= ""  Then  'determine if post has just submitted a form, then get form content output Cookies  If UCase(Trim(Request.ServerVariables ("Request_method"))) = "POST"  ThensUserName= Trim(Request.Form ("name")) Response.Cookies ("name") =sUserName Response.Cookies ("name"). Expires= DATEADD("D", 1,  Now)    'cookies expire after one dayResponse.Write ("I have already remembered your name! ")  Else    'Otherwise, the form is displayed so that the user submits the form%>    <formMethod= "POST"Action="">please tell me your name:<inputname= "Name"type= "text"/>    <inputtype= "Submit"value= "Submit" />    </form><%  End If ElseResponse.Write ("Hello," &sUserName)End If%></Body></HTML>

First run, unable to get Cookies information, display the form, let the user submit, such as:

Submit a form, or post to the current ASP page, because you still can't get cookies, so display the page that submitted the form successfully, such as:

Refresh the current page requestcookies.asp again, as you can get a cookie to display the visitor's name directly.

We explain in detail the part that lets the user enter the name and save, first get the value of the ServerVariables variable Request_method, which identifies the current page request method, if it is the post method, it is now thinking this page to submit a form, This is the time to get the value of the form and use the Response.Cookies collection to output cookies to the client, otherwise display the HTML code for the user to fill in the name.

Small Knowledge

The Trim function removes spaces on either side of the string, theLTrim function deletes the left space of the string, and theRTrim function removes the right space.

The UCase function converts the specified string to uppercase, and theLCase function converts the specified string to lowercase.

Sample code Download

Requestcookies.rar

Introduction to ASP (eight)-request object small case

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.