Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

TOPIC:

Request And Response Objects


CONTENTS
What Is ASP?
Creating An ASP Document
How Does ASP Works?
What Is request Obect In ASP
!arious "equest #etho$s
What Is "es%onse Obects In ASP
Summar&
LOVELY INSTITUTE OF MANAGEMENT
NAME: SAGAR KAPOOR
ROLL NUMBER: 7114233721
CLASS: BCA 6
TH
Sem, Se !C "
SUBMITTE# TO :
WHAT IS ASP?
ASP Stands for Active Server Pages (ASP), also known as Classic ASP or ASP
Classic, was Microsoft's first server-side script engine for dynamically-generated web
pages !nitially released as an add-on to!nternet !nformation Services (!!S) via
t"e #indows $% &' (ption Pack, it was s)bse*)ently incl)ded as a free component of
#indows Server (since t"e initial release of #indows +''' Server) !t "as now been
s)perseded by ASP$,%
-eveloping f)nctionality in ASP websites is enabled by t"e active scripting engine's
s)pport of t"e Component (b.ect Model (C(M), wit" eac" ob.ect providing a related
gro)p of fre*)ently-)sed f)nctions and data attrib)tes !n ASP +' t"ere were si/ b)ilt-
in ob.ects0 Application, ASP,rror, 1e*)est, 1esponse, Server, and Session
Session, for e/ample, is a cookie-based session ob.ect t"at maintains t"e state
of variables from page to page 2)nctionality is f)rt"er e/tended by ob.ects w"ic", w"en
instantiated, provide access to t"e environment of t"e web server3 as an
e/ample 2ileSystem(b.ect (2S() is )sed to create, read, )pdate and delete files
#eb pages wit" t"e .asp file e/tension )se ASP, alt"o)g" some #eb sites disg)ise t"eir
c"oice of scripting lang)age for sec)rity p)rposes (eg still )sing t"e more
common ."tm or ."tml e/tension) Pages wit" t"e .asp/ e/tension are ASP$,% (based
on Microsoft's $,% 2ramework) and compiled, w"ic" makes t"em faster and more
rob)st t"an server-side scripting in ASP w"ic" is interpreted at r)n-time3 "owever, many
ASP$,% pages still incl)de some ASP scripting S)c" marked differences between
ASP and ASP$,% "ave led to t"e terms Classic ASP or ASP Classic being )sed, w"ic"
also implies some nostalgia for t"e simpler platform
Most ASP pages are written in 45Script, b)t any ot"er Active Scripting engine can be
selected instead by )sing t"e 67ang)age directive or t"e 8script lang)age9:lang)age:
r)nat9:server:; synta/ <Script (Microsoft's implementation of ,CMAScript) is t"e ot"er
lang)age t"at is )s)ally available PerlScript (a derivative of Perl) and ot"ers are
available as t"ird-party installable Active Scripting engine
Creating An ASP Document
Creating an ASP doc)ment is easy %o begin coding ASP yo) need only two t"ings0 a
simple-te/t editor like notepad or %e/tpad or ,ditpl)s and t"e dedication to follow o)r
t)torial= $otepad is t"e most basic of simple-te/t editors and yo) will probably code a
fair amo)nt of >%M7 wit" it
#"en a browser re*)ests an ASP file, !!S passes t"e re*)est file to t"e ASP engine
%"e ASP engine reads t"e corresponding ASP file, line by line, and e/ec)tes t"e scripts
in t"e file 2inally, t"e ASP file is ret)rned to t"e browser as plain >%M7 format
ASP can connect to databases, dynamically format t"e page, e/ec)te statements, and
m)c" more ?o) may )se 45Script, <avaScript, Perl Script, and Pyt"on Script wit"in
Active Server Pages, wit" 45Script set as t"e defa)lt scripting lang)age #e
recommend t"at yo) )se 45Script as t"is s"o)ld do everyt"ing yo) need and is t"e
most commonly )sed
%"e appearance of an Active Server Page depends on w"at is viewing it An Active
Server Page looks .)st like a normal >%M7 page to t"e #eb browser t"at receives it !f
a visitor to yo)r #eb site views t"e so)rce code of an Active Server Page, t"at's w"at
t"ey see0 a normal >%M7 page >owever, t"e file located in t"e server looks very
different ?o) also see server-side scripts %"is is w"at t"e Active Server Page looks like
to t"e #eb server before it is processed and sent in response to a re*)est
HOW DOES ASP WORS?
>ow does an asp file, f)ll of calls to t"e ASP intrinsic ob.ects and ot"er components,
get translated into an >%M7 page t"at a standard browser can view (and e/ec)te)@ !n
fact, t"e process is reasonably simple0
%"e client re*)ests an ASP page by sending an >%%P Aet or Post 1e*)est to t"e
server All t"ings being e*)al, one of two t"ings will "appen "ere !f t"e server cannot
find t"e file t"en it responds wit" t"e familiar >%%P &'& $ot 2o)nd message !f t"e file is
fo)nd, it will be recogniBed as an Active Server Page beca)se of its .asp e/tension and
sent to t"e ASP Scripting engine to be parsed (All t"ings not being e*)al, t"en
somet"ing )ntoward C like a Server ,rror C may occ)r)
%"e Scripting >ost, located in asp.dll, can now do two t"ings0
!f t"is is t"e first ASP page to be sent to t"is client from t"e server, t"is means a new
session, and possibly a new application too, "as beg)n and it will c"eck globalasa for
anyt"ing to do before it gets to t"e re*)ested page (nce t"at "as been done, or if t"is
is not t"e first ASP page t"e client "as re*)ested, t"e "ost t"en e/ec)tes all t"e server-
side scripting code in t"e page as delimited by eit"er 8D D; or 8SC1!P%
1E$A%9SERVER> ... </SCRIPT> tags (nce t"is "as been done, t"e engine passes
back one of t"ree t"ings0 an error page, an ob.ect moved stat)s code, or an >%M7
page
!f eit"er an error page or a correctly-formed >%M7 page is passed back, it is t"en
displayed !f t"e ASP page contained a call to 1esponse.1edirect, t"e server will pass
back to t"e client t"e >%%P code F'+ telling it t"at t"e page re*)ested "as moved
temporarily $ote t"at if response b)ffering "ad previo)sly been set to tr)e, it will seem
to t"e client t"at t"e server a)tomatically transferred "im to t"e new location of t"e
page !f response b)ffering is set to false, w"ic" is t"e c)rrent ASP defa)lt, t"ey will see
an error page telling t"em t"e page t"ey wanted "as moved temporarily
W!at is Request Object In ASP?
%"e 1e*)est ob.ect retrieves t"e val)es t"at t"e client browser passed to t"e server
d)ring an >%%P re*)est !t is )sed to get information from t"e )ser Esing t"is ob.ect,
yo) can dynamically create web pages and perform vario)s server-side actions based
on inp)t from t"e )ser
#"en we s)rf to an address t"at begins wit" >%%P, t"e server we are visiting treats t"at
as an :>%%P re*)est:3 yo) are in fact :re*)esting: t"at a partic)lar web page is
displayed to yo) %"e same applies to any "ttp "yperlinks t"at yo) click A lot more
information is being passed back and fort", between yo)r PC and t"e server of t"e site
yo)'re visiting, t"an yo) may be aware of %"is c")nk of data is called a :re*)est
ob.ect: Along wit" t"e E17 we "ave re*)ested, information abo)t yo)r browser, !P
address, t"e last E17 we visited and more is being sent along wit" o)r re*)est to view a
partic)lar web page (n t"e flip side, in addition to t"e web page we re*)ested, t"e
server also sends back server-related information in t"e same re*)est ob.ect
All t"is data gets passed in t"e >%%P re*)est (aka 1e*)est (b.ect) #"et"er it was
posted via an online form yo) filled in or embedded in t"e E17 as name-val)e pairs, it
all ends )p in t"e 1e*)est ob.ect >ow does t"at "appen, yo) wonder@ %"at's a "elpf)l
feat)re of Microsoft !!S (internet information services), w"ereas systemsGlang)ages
s)c" as Eni/GPerl m)st parseGe/tract t"at information man)ally
%o make life a little simpler, t"e 1e*)est (b.ect "as several :collections: A collection is
.)st a fancy word for gro)ping, segregating or classifying all of t"e information t"at's
being e/c"anged 2or e/ample, inp)t-capable fields on a form t"at is sent via
:met"od9post: end )p in collection :2orm:, w"ile name-val)e pairs sent in t"e E17 (or
from a form sent via :met"od9get:) end )p in collection :H)eryString:, etc
%"e synta/, collections, properties and met"ods of t"e ASP 1e*)est ob.ect are as
follows0
1e*)estIcollectionJpropertyJmet"odK(variable)
Collections
Co""ections Description
ClientCertificate %"e ClientCertificate collection provides access to t"e certification
fields from a re*)est iss)ed by t"e web browser Commonly, it
is )sed w"en t"e client is re*)esting sec)re pages t"ro)g" SS7
connection 5efore )sing t"is collection, yo) m)st config)re yo)r #eb
server to re*)est client certificates
Cookies %"e Cookies collection allows yo) to retrieve t"e val)es of t"e
cookies sent in an >%%P re*)est
2orm %"e 2orm collection allows yo) to retrieve t"e data inp)t into an
>%M7 form posted to t"e >%%P re*)est body by a form )sing t"e
P(S% met"od
H)eryString %"e H)eryString collection allows to retrieve t"e val)es of t"e
variables in t"e >%%P *)ery string 2or e/ample, it parses t"e val)es
sent by a form )sing t"e A,% Met"od %"e H)eryString collection is
less capable t"an t"e 2orm collection, since t"ere is a limit to t"e
amo)nt of data t"at can be sent in t"e "eader of an >%%P re*)est
Server4ariables %"e Server4ariables collection contains t"e val)es of predefined
environment variables pl)s all of t"e >%%P "eader val)es sent from
t"e client browser to t"e web server
Properties
Properties Description
%otal5ytes %"e %otal5ytes property is a read-only property t"at specifies t"e total
n)mber of bytes sent by t"e client in t"e >%%P re*)est body !t is
important w"en preparing to read data from t"e re*)est body )sing
t"e 5inary1ead met"od of t"e 1e*)est ob.ect
Met"ods
#et!ods Description
5inary1ead %"e 5inary1ead met"od retrieves t"e data sent to t"e server from t"e
client as part of a P(S% re*)est and stores it in a SafeArray A
SafeArray is a special variant array t"at contains, in addition to its
items, t"e n)mber of dimensions in t"e array and t"e )pper bo)nds of
t"e array

$arious Request #et!od In ASP
1esponse ob.ect is )sed to re*)est information eit"er from t"e )ser (by means of form)
or from t"e server%"ere are many met"ods assigned to itSome of t"em t"at are )sed
mostly are0
! Request%&orm'(parameter()
%"is is )sed to get information passed from a 2(1M wit" t"e met"od of :P(S%:
E"a#ple:
8form name9:formLname: met"od9:post: action9:t"isLpageasp:;
8inp)t type9:te/t: name9:c)stomerLname: val)e9::;
8inp)t type9:password: name9:c)stomerLpassword: val)e9::;
8inp)t type9:s)bmit: name9:b)tton: val)e9:S)bmit:;
8Gform;
$! Request%quer*string'(parameter()
5asically,#e will find t"at t"is statement is same as re*)estform(:parameter:) %"e
difference is t"at t"is can be obtained not only from 2(1M wit" t"e met"od of :A,%: b)t
also from direct )rl typing
E"a#ple:
8form name9:formLname: met"od9:get: action9:t"isLpageasp:;
8inp)t type9:te/t: name9:c)stomerLname: val)e9::;
8inp)t type9:password: name9:c)stomerLpassword: val)e9::;
8inp)t type9:s)bmit: name9:b)tton: val)e9:S)bmit:;
8Gform;
+) Request%ser,er,ariab"es'(prede&ined-ser,er-,ariab"e()
Enlike t"e ot"er two above,we donMt "ave to get some val)es first before retrieving
server variables All t"ese information are located at server, available for re*)est
anytime we need it, s)c" as 2ollows00
a.%ro&ser infor#ation
8D9re*)estservervariables(:>%%PLES,1LAA,$%:)D;
'.(ocal IP Address
8D9re*)estservervariables(:7(CA7LA--1:)D;
c. )R(
8D9re*)estservervariables(:E17:)D;
d Re*+est #et,od
8D9re*)estservervariables(:1,HE,S%LM,%>(-:)D;
e. -ile na#e
8D9re*)estservervariables(:SC1!P%L$AM,:)D;
Response Object In ASP
%"e 1esponse ob.ect in ASP is )sed to send o)tp)t to t"e client from t"e web server
%"e 1e*)est ob.ect retrieves t"e val)es t"at t"e client browser passed to t"e server
d)ring an >%%P re*)est !t is )sed to get information from t"e )ser Esing t"is ob.ect,
we can dynamically create web pages and perform vario)s server-side actions based
on inp)t from t"e )ser !ts collections, properties, and met"ods are described below0
Co""ections.
Collection -escription
Cookies Sets a cookie val)e !f t"e cookie does not e/ist, it will be created, and
take t"e val)e t"at is specified
Properties
Property -escription
5)ffer Specifies w"et"er to b)ffer t"e page o)tp)t or not
Cac"eControl Sets w"et"er a pro/y server can cac"e t"e o)tp)t generated by
ASP or not
C"arset Appends t"e name of a c"aracter-set to t"e content-type "eader
in t"e 1esponse ob.ect
Content%ype Sets t"e >%%P content type for t"e 1esponse ob.ect
,/pires Sets "ow long (in min)tes) a page will be cac"ed on a browser
before it e/pires
,/piresAbsol)te Sets a date and time w"en a page cac"ed on a browser will
e/pire
!sClientConnected !ndicates if t"e client "as disconnected from t"e server
Pics Appends a val)e to t"e P!CS label response "eader
Stat)s Specifies t"e val)e of t"e stat)s line ret)rned by t"e server
#et!ods
#et!od Description
Add>eader Adds a new >%%P "eader and a val)e to t"e >%%P response
Append%o7og Adds a string to t"e end of t"e server log entry
5inary#rite #rites data directly to t"e o)tp)t wit"o)t any c"aracter conversion
Clear Clears any b)ffered >%M7 o)tp)t
,nd Stops processing a script, and ret)rns t"e c)rrent res)lt
2l)s" Sends b)ffered >%M7 o)tp)t immediately
1edirect 1edirects t"e )ser to a different E17
#rite #rites a specified string to t"e o)tp)t
1esponse (b.ect is one of t"e most important ob.ects in ASP !t is t"e ob.ect w"ic"
comm)nicates between t"e server and t"e o)tp)t w"ic" is sent to t"e client %o write an
ASP page, all we need to do is write a standard >%M7 page, p)tting in t"e Active Server
Pages script w"ere needed Active Server Pages script is denoted by t"e te/t
between 8D's and D;'s
%o send ASP to t"e client,we need to )se t"e 1esponse ob.ect %"e met"od of t"e
1esponse ob.ect w"ic" sends data to t"e client is t"e #rite met"od 2or e/ample, if yo)
write an >%M7 page w"ic" looks like0
8D6 7A$AEAA,9:45SC1!P%: D;
8>%M7;
85(-?;
8D 1esponse#rite(:>ello, #orld=:) D;
8G5(-?;
8G>%M7;
if a )ser views t"e page wit" a standard browser, t"ey will see t"e te/t, :>ello, #orld=:
on t"e screen !t's as if yo) "ad .)st written an >%M7 page wit" t"e words :>ello,
#orld=: w"ere t"e 8D's t"e te/t between and t"e D;'s were (f co)rse, )nlike an >%M7
page w"ic" is sent directly to t"e client, t"is page "as passed t"ro)g" t"e server's
ASP-77, parsing it so t"at instead of t"e client seeing8D 1esponse#rite(:>ello,
#orld=:) D;, t"e client merely sees :>ello, #orld=: ,ven if t"e )ser goes to 4iew So)rce
in t"eir browser, t"ey will only see t"e :>ello, #orld=: %"is is beca)se t"e client is never
sent t"e preprocessed ASP script
we can in"erently invoke t"e 1esponse#rite met"od by )sing t"e e*)als (9) sign >ere
is an e/ample, w"ic" "appens to prod)ce t"e e/act same o)tp)t as above0
8D6 7A$AEAA,9:45SC1!P%: D;
8>%M7;
85(-?;
8D9:>ello, #orld=: D;
8G5(-?;
8G>%M7;
As we notice, we .)st got rid of t"e 1esponse#rite( ), b)t left t"e st)ff in between
%"e 9 sim)lates 1esponse#rite
%"ere are also a few ot"er neat properties in t"e 1esponse ob.ect (ne is ,/pires,
w"ic" sets "ow soon o)r page e/pires Many modern browsers cac"e pages for *)icker
downloading times
#e can )se ASP to set "ow often t"e browser c"ecks to see if it needs to redownload
t"e page ?o) set it in terms on min)tes !f yo) want to browser not to cac"e t"e page,
yo) can set 1esponse,/pires 9 ' 7et's look at an e/ample w"ere we set t"e page to
e/pire in N' min)tes
8D6 7A$AEAA,9:45SC1!P%: D;
8D
1esponse,/pires 9 N'
D;
8>%M7;
85(-?;
%"is page will e/pire in N' min)tes
8G5(-?;
8G>%M7;
S/##AR0
Active Server Pages (ASP) was Microsoft's first server-side script engine for
dynamically-generated web pages !t is also known as Classic ASP or ASP Classic !t
"as now been replaced by ASP$,% !t is a server side tec"nology t"at enables )s to
make dynamic and interactive web pages t"at are not affected by t"e type of browser
t"e web site visitor is )sing
%"e 1e*)est ob.ect retrieves t"e val)es t"at t"e client browser passed to t"e server
d)ring an >%%P re*)est !t is )sed to get information from t"e )ser Esing t"is ob.ect,
yo) can dynamically create web pages and perform vario)s server-side actions based
on inp)t from t"e )ser
%"e 1esponse ob.ect in ASP is )sed to send o)tp)t to t"e client from t"e web server
%"e 1e*)est ob.ect retrieves t"e val)es t"at t"e client browser passed to t"e server
d)ring an >%%P re*)est !t is )sed to get information from t"e )ser Esing t"is ob.ect,
we can dynamically create web pages and perform vario)s server-side actions based
on inp)t from t"e )ser

You might also like