JavaScript ASP Tutorial Eighth lesson--request Object _asp Foundation

Source: Internet
Author: User
Tags html form servervariables

Request Object:

Request has five (5) collections, one (1) property, and one (1) method. You'll use the collections far to than the property or the "method."

Request Collections:

Below is a table of the Request collections and descriptions to how they are used.

Request Collections
ClientCertificate Request.clientcertificate ("Key[field]")
Client Security Info for SSL encryption
Cookies Request.Cookies ("CookieName")
Holds cookie value stored on the client
Form Request.Form ("FormName")
Holds value sent via HTML Form
QueryString Request.QueryString ("KeyName")
Name/value pair appended to the "end of" the URL
ServerVariables Request.ServerVariables ("VariableName")
Hold values sent in the HTTP Headers

ClientCertificate:

Request.clientcertificate is used with S.S.L. (Secure Sockets Layer). It is beyond the scope of this web site.

Cookies:

We'll learn Request.Cookies and response.cookies together in Lesson 08. Please be patient.

Form:

Request.Form is probably the workhorse of the Request collections. The repeat from Lesson 03.

 <% @LANGUAGE = "JavaScript"%> <%//no ASP here, just a regular HTML Page%> <HTML> <strong>type Something into the text box and submit it.</strong> <form action= "script08a.asp" method= "Post" > <input TYPE = "Text" name= "webpagevariable" ><BR> <strong>how much money does you have each month?</strong><br&
Gt <select name= "Monthlysalary" > <option>under $5,000,000</option> <option>above $5,000,000 </OPTION> <option>nobody ' s darn business.</option> </SELECT><BR> <input type= " Submit "value=" "Submit" > </FORM> </HTML> 

Click here to run script08.asp in a new window. It posts information to script08a.asp which is found below. In turn, script08a.asp posts information to script08b.asp which is also found.

 <% @LANGUAGE = "JavaScript"%> <% var webpagevariable = new String (Request.Form ("webpagevariable"))

webpagevariable = Webpagevariable.touppercase ();
var monthlysalary = new String (Request.Form ("Monthlysalary")) Monthlysalary = Monthlysalary.tolowercase ();  %> <HTML> The Web Page Variable you typed are: <%=WebPageVariable%> <BR> the monthly salary you listed is: <%=monthlySalary%> <BR> <form action= "script08b.asp" method= "get" > <input type= "hidden" VALUE = "<%=monthlySalary%>" name= "queryvariable" > <strong>click the button to Query Strings</strong ><BR> <input type= "Submit" value= "Submit" > </FORM> </HTML> 

We ' ll be using request.form when we ' Post ' a HTML Form to the server. Notice that's name in the HTML form corresponds to the ' name ' in request.form (' name ') . To being more specific, <input type= "Text" name= "webpagevariable" > corresponds with request.form ("WebP Agevariable ") . We already talked about the need for the new String () constructor back in Lesson 03.

QueryString:

We are using request.querystring when we use an HTML form to "get" a page from the server. Request.QueryString () is very similar to Request.Form (). Take a look at script08b.asp which I printed below.

<% @LANGUAGE = "JavaScript"%>
<%
var queryvariable = new String (Request.QueryString ("queryvariable") )
%>
<HTML> The
querystring Value is: <%=QueryVariable%> <BR>
<%
if ( Queryvariable!= "Lesson ' new query!")
	{
	queryvariable= "Lesson ' s new query!"
	Queryvariable=escape (queryvariable)
%>
<a href= "script08b.asp? Queryvariable=<%=queryvariable%> ">click here</a> for the 
link to <i>script08b.asp? queryvariable=<%=queryvariable%></i>
<%
	}//closing bracket for if statement.
%>
</HTML>

If you are haven ' t already, Click here to run script08.asp in a new window. Cycle through the forms and links, and then come back.

can use Request.QueryString in two different ways. You can either use an HTML form to ' get ' a page from the server, which'll generate a query string. Or You can manually builds a query string and add it to the backside of a link. We ' ll dissect script08b.asp from top to bottom.

var queryvariable = new String (Request.QueryString ("queryvariable"))

The line above in script08b.asp corresponds to the line below from script08a.asp

<input type= "hidden" value= "<%=monthlySalary%>" name= "queryvariable" >

The Name= "Somename" in the HTML form becomes the request.querystring ("Somename") on the next page.

About half way into script08b.asp are lines I reprinted.

<%
if (queryvariable!= "Lesson ' new query!")
	{
	queryvariable= "Lesson ' s new query!"
	Queryvariable=escape (queryvariable)
%>

We ' ve already converted Request.QueryString () into a JavaScript string at the top of the script. So, now we can do a string comparison.

If the queryvariable hasn ' t already been set equal to "Lesson" The new query! "we" then. Then we use the Escape () method to convert white spaces and special characters into Unicode. (URL ' s should contain neither whitespace, nor most special characters.)

In lesson we'll have a better way to encode URL ' s. When we study the Server Object, we ll Server.URLEncode (). But for today, just know that escape ().

Can have more than one querystring in each page. If you lose count of your querystrings, then your use Request.QueryString.Count to tell you the number.

The Request shortcut:

Request.Form () and Request.QueryString () share a shortcut. Request.Form ("webpagevariable") can be abbreviated as Request ("webpagevariable") and Request.QueryString ("queryvariable") can be abbreviated as Request ("queryvariable") .

ServerVariables:

The server Variables represent the HTTP Headers sent to the server by the client. I won ' t demonstrate them, because there are too.

<% @LANGUAGE = "JavaScript"%>
<HTML>
<table border= "1" >
<tr><td>all_raw </TD>
<td><%=request.servervariables ("All_raw")%></td></tr>
<TR> <TD>REMOTE_ADDR</TD>
<td><%=request.servervariables ("REMOTE_ADDR")%></td> </TR>
<TR><TD>HTTP_USER_AGENT</TD>
<td><%=request.servervariables (" Http_user_agent ")%></td></tr>
<TR><TD>URL</TD>
<td><%= Request.ServerVariables ("URL")%></td></tr>
</TABLE>
</HTML>

Click here to run the script in a new window.

Demonstrated above are four (4) server variables. There are (give or take) is about server variables available. You can look up the ' full list ' of server variables for yourself on the Internet.

Misc. Notes:

The

Request.BinaryRead () is the lone property of the lone method and TotalBytes. Request.BinaryRead (request.totalbytes) retrieves the data from an HTML form using "POST." You must supply the totalbytes as a argument. It stores the data into an array. BinaryRead cannot is used at the same time as Request.Form ().

Related Article

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.