Programming.a.baby - (Asp) Object Request
By pol1ce
Article 5
Objects
If you follow my last article ( Programming.a.baby (Asp) Object Response ), you did learn about one object, the Response Object, now we will learn about another one, the Request Object.
With this one you can already start to have many ideas about what you can invent and do, because since this Object can have a interaction with the user's browser, you can play with it to gain some experience.
Remember that One Server Object is something that the We Server creates for you after receiving some information with your Asp Script.
Is true that some Browsers also can create some Script Object when using some type of Browser Script like Javascript, Jscript, VBScript,Active Script... But remember that we are working here with a Server Script Language, all works in the server, very secure since the user cannot see the script source, all that he sees is the Output Html
Code Sample 1.1
<% Request.Cookies Request.Form Request.Querystring Request.ServerVariables %>
Code Sample 1.2
<%
Request.Querystring("")
%>Object Request List
This is a list of the Collections that the Request Object can capture
Cookies
Form
Querystring
ServerVariables
We only want to talk about the Querystring Collection for now, OK!
Request Querystring
What is a Querystring?
Do you already saw some web sites adresses with some "?" take these examples
- http://www.somewebsiteee.com/?nick=kevin
- http://www.somewebsiteee.com/folder/?id=123
- http://www.somewebsiteee.com/folder/page.asp?key=albert
Take the example of the first one ?name=kevin
- "?" Is the Querystring
- "nick" Is name of the Querystring
- "kevin" is the content of the Querystring
So you can use your own page that is something like this
- www.mysitesomewhere.com/default.asp
Take a look in the image bellow:
Code Sample 2.1
<%
Dim name
name = Request.Querystring("name")
Response.Write name
%>Requesting the QueryString
Now in the same web page we will:
- We Declare one VARiable (Dim) with a name of your choice
- We give this VAR a content of the Querystring "name" by Requesting it
- We tell the Server to Response Write the VARiable with Querystring Value
Check the Code Sample 2.1 at Right:
Sample 2.2
<%
Dim name
name = Request.Querystring("name")
If name = "simon Then
Response.Write name
Else
Response.Write "unknown"
End If
%>Conditional Request
Lets suppose that you want only to Write the VARiable corresponding to the Requesting QueryString, IF the name is "simon", ELSE you will tell the server to Write other thing.
So, you can use the IF Statement to cause a condition inside your Asp script.
The IF Statement in Asp is more simple than the other languages, since there is no Brackets "{}", "()", "[]"
More Request of Info
Remember that the Querystring Requests are only to be use with small information, please do not write a book after a "?" since the Request Object may cannot handle this.
The syntax for requesting more querystrings within one only web address is to add a second one that must always be with a "&", Example:
- www.mywebsitesomewhere.com/?name=simon
- www.mywebsitesomewhere.com/?name=simon&age=65
- www.mywebsitesomewhere.com/?name=simon&age=65&country=portugal
In the next Article i will teach you how to request big peaces of information using the Object Request with Html Forms.
Meanwhile take a look at the Sample 3 - Code and the Sample 3 - Output
Sample 3 - The Right Code
<%@ Language="VBScript" %>
<% OPTION EXPLICIT %>
<%
Dim name
Dim age, country
name = Request.Querystring("name")
age = Request.Querystring("age")
country = Request.Querystring("country")
Response.Write name & "<br />"
Response.Write age & "<br />"
Response.Write country
%>Sample 3 - Html Output
simon 65 portugal
More Articles like This One
.
Next -->
6) Programming.a.baby - (Asp) Request Object (Quiz)
|||
<-- Previous
4) Programming.a.baby - (Asp) Object Response
3) Programming.a.baby - (Asp) The Asp Variables
2) Programming.a.baby - (Asp) My first Asp Page
1) Programming.a.baby - (Asp) Asp what is it
.
Comments
No comments yet.