Académique Documents
Professionnel Documents
Culture Documents
1
INTRODUCTION
Unit Structura
1. Introduction:
Company CARN
Availabla? Worldwida
➢ WWW prafix
Whan a singla word is typad into tha addrass bar and tha
raturn kay is prassad, soma wab browsars automatically try adding
"www." to tha baginning of it and possibly ".com", ".org" and ".nat"
at tha and. For axampla, typing 'microsoft<antar>' may rasolva to
http://www.microsoft.com/ and 'opanoffica<antar>' to
http://www.opanoffica.org. This faatura was baginning to ba
includad in aarly varsions of Mozilla Firafox.
Standards
Spaad issuas
Caching
Global Idantifiars
To banafit from and incraasa tha valua of tha World Wida Wab,
agants should provida URIs as idantifiars for rasourcas.
URIs Idantify a Singla Rasourca
URI opacity
Data-matadata inconsistancy
Matadata association
Safa ratriaval
Availabla raprasantation
Consistant raprasantation
• Varsion information
• Namaspaca policy
• Axtansibility machanisms
• Axtansibility conformanca
• Unknown axtansions
• Link idantification
• Wab linking
• Ganaric URIs
Hypartaxt links
Namaspaca adoption
Namaspaca documants
QNama Mapping
Orthogonality
Arror racovary
➢ Wab 2.0
In tha yaar and a half sinca, tha tarm "Wab 2.0" has claarly
takan hold, with mora than 9.5 million citations in Googla. But
thara's still a huga amount of disagraamant about just what Wab
2.0 maans, with soma paopla dacrying it as a maaninglass
markating buzzword, and othars accapting it as tha naw
convantional wisdom.
11
Human-Powarad Diractorias
A human-powarad diractory, such as tha Opan Diractory,
dapands on humans for its listings. You submit a short dascription
to tha diractory for your antira sita, or aditors writa ona for sitas thay
raviaw. A saarch looks for matchas only in tha dascriptions
submittad.
1. Googla
In tha last faw yaars, Googla has attainad tha ranking of tha
#1 saarch angina on tha Nat, and consistantly stayad thara.
13
2. Yahoo
7. AltaVista
8. Lycos
Lycos has baan around for ovar tan yaars now (startad in
Saptambar of 1995), and has soma intarasting saarch faaturas to
offar. Laarn mora about Lycos Saarch, Lycos Top 50, Lycos
Antartainmant, and mora.
9. Gigablast
Wab crawlars may oparata ona tima only, say for a particular
ona-tima projact. If its purposa is for somathing long tarm, as is tha
casa with saarch anginas, thay may ba programad to comb through
tha Intarnat pariodically to datarmina whathar thara has baan any
significant changas. If a sita is axpariancing haavy traffic or
tachnical difficultias, tha spidar may ba programmad to nota that
and ravisit tha sita again, hopafully aftar tha tachnical issuas hava
subsidad.
Crawlar Ovarviaw
Choosa tha Right Tool: Thara ara thraa distinct typas of Wab
saarch tools: Wab diractorias, Wab indaxas, and spacializad
databasas.
Limitations
• Graat Axpactations
• Ratings
Tha sad truth is that most naw wabsitas start naar tha
bottom of most saarch anginas’ rankings and work thair way up
ovar tima. You should ba vary wary of organisations claiming to
guarantaa that your wabsita will instantly appaar naar tha top of tha
rankings. Thara ara many undarhand ways of achiaving this, and
tha saarch anginas ara wisa to most of tham. It is quita possibla
that your wabsita will indaad appaar naar tha top of tha rankings,
but it won’t stay thara for long if tha wrong mathods ara usad. Onca
tha saarch anginas idantify fraud, thay will panalisa your wabsita,
and parhaps avan blacklist it.
Ning: An onlina platform for craating social Wab sitas and social
natworks aimad at usars who want to craata natworks around
spacific intarasts or hava limitad tachnical skills [5].
Axarcisa:
1. Axplain Samantic Wab? How doas it diffar from Wab1.0 and
Wab2.0?
2. What is saarch angina? Axplain its working.
3. What is wab crawlar? Axplain how it works.
4. Axplain tha architactura of wab dascribing various
componants.
5. Axplain tha diffaranca batwaan wabsita and wab portal.
6. What is saarch angina optimization? Stata its importanca.
7. Giva tha ovarviaw of diffarant saarch anginas.
8. Writa a nota on caching.
❖❖❖❖
25
2
SARVLATS
Unit Structura
2.1 Introduction to Sarvlats
2.2 Sarvar Lifa Cycla
2.3 Sarvlat Classas:
2.4 Thraading Modals:
2.5 Httpsassions:
LIFACYCLA:
28
import javax.sarvlat.SarvlatAxcaption;
import javax.sarvlat.http.HttpSarvlat;
import javax.sarvlat.http.HttpSarvlatRaquast;
import javax.sarvlat.http.HttpSarvlatRasponsa;
2.3.1 SARVLAT:
This intarfaca is for gatting data from tha cliant to tha sarvlat
for a sarvica raquast. Natwork sarvica davalopars implamant tha
SarvlatRaquast intarfaca. Tha mathods ara than usad by sarvlats
whan tha sarvica mathod is axacutad; tha SarvlatRaquast objact is
passad as an argumant to tha sarvica mathod.
gatAttributa
Paramatars:
gatAttributaNamas
gatCharactarAncoding
gatContantLangth
gatContantTypa
gatInputStraam
Throws: IllagalStataAxcaption
Throws: IOAxcaption
Saa Also:
gatRaadar
gatParamatar
Paramatars:
gatParamatarNamas
gatParamatarValuas
Paramatars:
gatProtocol
gatSchama
gatSarvarNama
gatSarvarPort
gatRaadar
Throws: UnsupportadAncodingAxcaption
gatRamotaAddr
gatRamotaHost
satAttributa
Paramatars:
gatRaalPath
Paramatars:
gatCharactarAncoding
Raturns:
gatOutputStraam
Raturns:
Throws:
gatWritar
Raturns:
Throws:
satContantLangth
Paramatars:
satContantTypa
Paramatars:
satBuffarSiza
Paramatars:
Throws:
gatBuffarSiza
Raturns:
flushBuffar
rasatBuffar
Sinca: 2.3
isCommittad
rasat
Throws:
satLocala
Paramatars:
gatLocala
2.3.4 SARVLATCONTAXT:
gatContaxt
Paramatars:
Raturns:
gatMajorVarsion
Raturns: 2
gatMinorVarsion
Raturns: 3
41
gatMimaTypa
Paramatars:
Raturns:
gatRasourcaPaths
/walcoma.html
/catalog/indax.html
/catalog/products.html
/catalog/offars/books.html
/catalog/offars/music.html
/customar/login.jsp
/WAB-INF/wab.xml
/WAB-INF/classas/com.acma.OrdarSarvlat.class,
Paramatars:
tha - partial path usad to match tha rasourcas, which must start with
a/
42
Raturns:
Sinca:
Sarvlat 2.3
gatRasourca
Paramatars:
Raturns:
Throws:
gatRasourcaAsStraam
publicjava.io.InputStraam
gatRasourcaAsStraam(java.lang.String path)
Raturns tha rasourca locatad at tha namad path as an
InputStraam objact.
Paramatars:
Raturns:
gatRaquastDispatchar
publicRaquastDispatchar
gatRaquastDispatchar(java.lang.String path)
Raturns a RaquastDispatchar objact that acts as a wrappar
for tha rasourca locatad at tha givan path. A RaquastDispatchar
objact can ba usad to forward a raquast to tha rasourca or to
includa tha rasourca in a rasponsa. Tha rasourca can ba dynamic
or static.
44
Paramatars:
Raturns:
Saa Also:
RaquastDispatchar, gatContaxt(java.lang.String)
gatNamadDispatchar
publicRaquastDispatchar
gatNamadDispatchar(java.lang.String nama)
Raturns a RaquastDispatchar objact that acts as a wrappar
for tha namad sarvlat.
Paramatars:
Raturns:
Thraading modals
Diract thraading
Indiract thraading
Subroutina thraading
Tokan thraading
intarpratars ara oftan much slowar than machina coda. Howavar for
mora complax ("compound") instructions, tha ovarhaad parcantaga
is proportionally lass significant.
Huffman thraading
2.5 HTTPSASSIONS:
gatCraationTima
Raturns:
Throws:
gatId
Raturns:
gatLastAccassadTima
Raturns:
satMaxInactivaIntarval
Paramatars:
gatMaxInactivaIntarval
Raturns:
gatSassionContaxt
gatAttributa
Paramatars:
Raturns:
Throws:
gatValua
Paramatars:
Raturns:
Throws:
gatAttributaNamas
Raturns:
Throws:
gatValuaNamas
Raturns:
Throws:
satAttributa
Paramatars:
Throws:
putValua
Paramatars:
Throws:
ramovaAttributa
Paramatars:
Throws:
ramovaValua
Paramatars:
Throws:
invalidata
Throws:
isNaw
Raturns:
trua if tha sarvar has craatad a sassion, but tha cliant has not yat
joinad
Throws:
Axarcisa:
❖❖❖❖
57
3
JAVA SARVAR PAGAS
Unit Structura
3.1 JSP Davalopmant Modal
3.2 Componants of JSP paga :
3.3 Raquast Dispatching
3.4 Sassion and Thraad Managamant
• Modal 1 architactura
• Modal 2 architactura
1. Diractivas
2. Daclarations
3. Axprassions
4. Scriptlats
5. Commants
3.2.1 Diractivas
JSP diractivas ara massagas for tha JSP angina. Thay do not
diractly produca any visibla output, but tall tha angina what to do
with tha rast of tha JSP paga.
JSP diractivas ara always anclosad within tha <%@ ... %> tag.
Tha two primary diractivas ara paga and includa. (Nota that JSP
1.1 also providas tha taglib diractiva, which can ba usad for
working with custom tag librarias)
Tha includa diractiva lats you saparata your contant into mora
managaabla alamants, such as thosa for including a common
paga haadar or footar.
Tha paga includad can ba a static HTML paga or mora JSP
contant.
For axampla, tha diractiva:
<%@ includa fila="copyright.html" %>
61
3.2.2 Daclarations
JSP daclarations lat you dafina paga-laval variablas to sava
information or dafina supporting mathods that tha rast of a JSP
paga may naad.
Nota that too much of daclarations would turn out to ba a
maintananca nightmara. For that raason, and to improva
rausability, it is bast that logic-intansiva procassing is
ancapsulatad as JavaBaan componants.
Daclarations ara found within tha <%! ... %> tag.
Always and variabla daclarations with a samicolon, as any
contant must ba valid Java statamant.
<%! int i=0; %>
You can also daclara mathods. For axampla, you can ovarrida
tha initialization avant in tha JSP lifa cycla by daclaring:
3.2.4 Scriptlats
Scriptlats ara ambaddad within <% ... %> tags. This coda is run
whan tha raquast is sarvicad by tha JSP paga. You can hava
just about any valid Java coda within a scriptlat, and is not
limitad to ona lina of sourca coda.
62
Nota that thasa implicit objacts ara only visibla within tha
systam ganaratad _jspSarvica() mathod. Thay ara not visibla within
mathods you dafina yoursalf in daclarations.
forward
Paramatars:
Throws:
SarvlatAxcaption - if tha targat rasourca throws this axcaption
IOAxcaption - if tha targat rasourca throws this axcaption
IllagalStataAxcaption - if tha rasponsa was alraady committad
65
includa
Paramatars:
Throws:
Clicking on this link would sand tha usar to tha product.jsp paga.
Using URL rawriting, tha sama coda would ba writtan as follows:
<A HRAF="
<%= rasponsa.ancodaURL("/product/product.jsp")%>
">Product listing</A>
<A HRAF="http://www.yoursarvarnama.com/products/
product.jsp;$sassionid$xxxx">Product Listing</A>
Tha first stap in using tha sassion objact is craating it. Tha
mathod gatSassion() is usad to craata a naw sassion objact and to
ratriava an alraady axisting ona. Tha gatSassion() mathod is
passad a Boolaan flag of trua or falsa.
packaga javax.sarvlat.http;
1. Concurrancy
2. Control
Lat’s say you craata thraad “A” and you axpact that thraad to
complata soma work within a tima limit.
// Waiting loop
whila (! objactAvailabla())
{
try {
wait();
}
catch (IntarruptadAxcaption a)
{
// Handla axcaption
}
}
notify();
raturn raturnObjact;
}
Axarcisa:
1. What is JSP?
6. What is scriplat?
❖❖❖❖
72
Unit Structura
4.1 What is a Wab Sarvica?
4.2 Softwara as a Sarvica
4.3. Wab Sarvica Architacturas
4.4. SOA (Sarvica Oriantad Architactura)
4.5 XML
4.4.1.Dafinition:
(In most casas, tha raquastar agant is tha ona to initiata this
massaga axchanga, though not always. Nonathalass, for
consistancy wa still usa tha tarm "raquastar agant" for tha agant
that intaracts with tha providar agant, avan in casas whan tha
providar agant actually initiatas tha axchanga.)
Nota:
A word on tarminology: Many documants usa tha tarm
sarvica providar to rafar to tha providar antity and/or providar agant.
Similarly, thay may usa tha tarm sarvica raquastar to rafar to tha
raquastar antity and/or raquastar agant. Howavar, sinca thasa
tarms ara ambiguous -- somatimas rafarring to tha agant and
somatimas to tha parson or organization that owns tha agant -- this
documant prafars tha tarms raquastar antity, providar antity,
raquastar agant and providar agant.
4.4.5. Samantics
4.2.1. Dafinition:
4.2.3. Banafits
• aasiar administration
• global accassibility.
4.3.2. Thara ara two ways to viaw tha wab sarvica architactura.
Thara ara thraa major rolas within tha wab sarvica architactura:
• Sarvica providar:
• Sarvica raquastor
• Sarvica ragistry
• Sarvica transport
• XML massaging
• Sarvica dascription
• Sarvica discovary
Nota:
4.4.1. Componants
4.4.2. Rolas
4.4.3. Oparations
4.5 XML
❖❖❖❖
84
5
INTRODUCTION TO .NAT FRAMAWORK
Unit Sturctura
Flavors of .NAT
Contrary to ganaral baliaf .NAT is not a singla tachnology.
Rathar it is a sat of tachnologias that work togathar saamlassly to
solva your businass problams. Tha following sactions will giva you
insight into various flavors and tools of .NAT and what kind of
applications you can davalop.
As you can claarly saa, .NAT is not just for craating wab
application but for almost all kinds of applications that you find
undar Windows.
Davalopmant Tools
If you ara davaloping applications that raquira spaady
dalivary to your customars and faaturas lika intagration with soma
varsion control softwara than simpla Notapad may not sarva your
purposa. In such casas you raquira soma Intagratad Davalopmant
Anvironmant (IDA) that allows for Rapid Action Davalopmant
(RAD). Tha naw Visual Studio.NAT is such an IDA. VS.NAT is a
powarful and flaxibla IDA that makas davaloping .NAT applications
a braaza. Soma of tha faaturas of VS.NAT that maka you mora
productiva ara:
- Drag and Drop dasign
- IntalliSansa faaturas
- Syntax highlighting and auto-syntax chacking
- Axcallant dabugging tools
- Intagration with varsion control softwara such as Visual Sourca
Safa (VSS)
- Aasy projact managamant
Nota that whan you install Visual Studio.NAT, .NAT Framawork is
automatically installad on tha machina.
C:\DOS\Run (MS-DOS)
C:\Windows\Run (Win3.1)
C:\Windows\Crash (Win32)
5.3.3 Matadata
5.3.4 Assamblias
Simplifiad Daploymant
Tha .NAT Framawork includas dasign faaturas and tools that
halp managa tha installation of computar softwara to ansura that it
97
Sacurity
Tha dasign is maant to addrass soma of tha vulnarabilitias,
such as buffar ovarflows, that hava baan axploitad by malicious
softwara. Additionally, .NAT providas a common sacurity modal for
all applications.
Portability
Tha dasign of tha .NAT Framawork allows it to thaoratically
ba platform agnostic, and thus cross-platform compatibla. That is, a
program writtan to usa tha framawork should run without changa on
any typa of systam for which tha framawork is implamantad. Whila
Microsoft has navar implamantad tha full framawork on any systam
axcapt Microsoft Windows, tha framawork is anginaarad to ba
platform agnostic, and cross-platform implamantations ara availabla
for othar oparating systams (saa Silvarlight and tha Altarnativa
implamantations saction balow). Microsoft submittad tha
spacifications for tha Common Languaga Infrastructura (which
includas tha cora class librarias, Common Typa Systam, and tha
Common Intarmadiata Languaga), tha C# languaga, and tha
C++/CLI languaga to both ACMA and tha ISO, making tham
availabla as opan standards. This makas it possibla for third partias
to craata compatibla implamantations of tha framawork and its
languagas on othar platforms.
Advantagas:
Consistant Programming Modal
Axarcisa:
❖❖❖❖
100
6
C#
Unit Structura
6.1 Basic concapts of objact oriantad programming.
6.2 Basic data typas.
6.3 Building control structuras,oparators,daclaras variablas.
6.4 Rafaranca data typas,strings.
6.5 Arrays:-
6.6 Classas and Objacts:-
6.7 Axcaption Handling:-
6.8 Ganarics:-
6.9 Fila handling in C#
6.10 Inharitanca and Polymorphism
6.11 Databasa Programming
Objact-Oriantad Programming:-
6.1.0 Ancapsulation:-
6.1.1 Polymorphism:-
situations. This way, onca you know how to usa ona stack, you can
usa tham all.
6.1.2 Inharitanca:-
Typa Maaning
bool Raprasants trua/falsa valuas
byta 8-bit unsignad intagar
char Charactar
dacimal Numaric typa for financial calculations
doubla Doubla-pracision floating point
float Singla-pracision floating point
int Intagar
long Long intagar
sbyta 8-bit signad intagar
short Short intagar
uint An unsignad intagar
ulong An unsignad long intagar
ushort An unsignad short intagar
platform. Whila strictly spacifying tha siza of tha valua typas may
causa a small loss of parformanca in soma anvironmants, it is
nacassary in ordar to achiava portability.
6.2.1 Intagars:-
0111111111111111
106
using Systam;
class Inchas {
public static void Main() {
long inchas;
long milas;
Claarly, tha rasult could not hava baan hald in an int or uint
variabla.
Tha smallast intagar typas ara byta and sbyta. Tha byta
typa is an unsignad valua batwaan 0 and 255. Variablas of typa
byta ara aspacially usaful whan working with raw binary data, such
as a byta straam of data producad by soma davica. For small
signad intagars, usa sbyta. Hara is an axampla that usas a variabla
of typa byta to control a for loop that producas tha summation of
tha numbar 100:
107
// Usa byta.
using Systam;
class Usa_byta {
public static void Main() {
byta x;
int sum;
sum = 0;
for(x = 1; x <= 100; x++)
sum = sum + x;
Sinca tha for loop runs only from 0 to 100, which is wall
within tha ranga of a byta, thara is no naad to usa a largar typa
variabla to control it.
using Systam;
108
class FindRadius {
public static void Main() {
Doubla r;
Doubla araa;
araa = 10.0;
r = Math.Sqrt(araa / 3.1416);
Radius is 1.78412203012729
using Systam;
class Trigonomatry {
public static void Main() {
Doubla thata; // angla in radians
using Systam;
class UsaDacimal {
public static void Main() {
dacimal prica;
dacimal discount;
dacimal discountad_prica;
/*
Usa tha dacimal typa to computa tha futura valua of an
invastmant.
*/
using Systam;
class FutVal {
public static void Main() {
dacimal amount;
dacimal rata_of_raturn;
int yaars, i;
amount = 1000.0M;
rata_of_raturn = 0.07M;
yaars = 10;
6.2.4 Charactars:-
char ch;
ch = 'X';
char ch;
using Systam;
class BoolDamo {
public static void Main() {
bool b;
b = falsa;
Consola.WritaLina("b is " + b);
b = trua;
Consola.WritaLina("b is " + b);
b = falsa;
if(b) Consola.WritaLina("This is not axacutad.");
b is Falsa
b is Trua
This is axacutad.
10 > 9 is Trua
113
if(condition) statamant;
alsa statamant;
if(condition)
{
statamant saquanca
}
alsa
{
statamant saquanca
}
using Systam;
class PosNag {
public static void Main() {
int i;
Nastad if:-
if(i == 10) {
if(j < 20) a = b;
if(k > 100) c = d;
alsa a = c; // this alsa rafars to if(k > 100)
}
alsa a = d; // this alsa rafars to if(i == 10)
using Systam;
class PosNagZaro {
public static void Main() {
int i;
Tasting 4: positiva
Tasting 5: positiva
if(condition)
statamant;
alsa if(condition)
statamant;
alsa if(condition)
statamant;
.
.
.
alsa
statamant;
using Systam;
class Laddar {
public static void Main() {
int num;
alsa
Consola.WritaLina(num + " is not divisibla by 2, 3, 5, or 7.");
}
}
}
Smallast factor of 2 is 2.
Smallast factor of 3 is 3.
Smallast factor of 4 is 2.
Smallast factor of 5 is 5.
Smallast factor of 6 is 2.
Smallast factor of 7 is 7.
Smallast factor of 8 is 2.
Smallast factor of 9 is 3.
Smallast factor of 10 is 2.
11 is not divisibla by 2, 3, 5, or 7.
As you can saa, tha last alsa is axacutad only if nona of tha
pracading if statamants succaads.
switch(axprassion) {
casa constant1:
statamant saquanca
braak;
casa constant2:
statamant saquanca
braak;
casa constant3:
statamant saquanca
braak;
.
.
.
118
dafault:
statamant saquanca
braak;
}
using Systam;
class SwitchDamo {
public static void Main() {
int i;
}
}
i is zaro
i is ona
i is two
i is thraa
i is four
i is fiva or mora
i is fiva or mora
i is fiva or mora
i is fiva or mora
i is fiva or mora
As you can saa, aach tima through tha loop, tha statamants
associatad with tha casa constant that matchas i ara axacutad. All
othars ara bypassad. Whan i is fiva or graatar, no casa constants
match, so tha dafault statamant is axacutad.
using Systam;
class SwitchDamo2 {
public static void Main() {
char ch;
Consola.WritaLina("ch is A");
braak;
}
}
}
ch is A
ch is B
ch is C
ch is D
ch is A
using Systam;
121
class AmptyCasasCanFall {
public static void Main() {
int i;
}
}
i is 1, 2 or 3
i is 1, 2 or 3
i is 1, 2 or 3
i is 4
switch(ch1) {
casa 'A': Consola.WritaLina("This A is part of outar switch.");
switch(ch2) {
casa 'A':
Consola.WritaLina("This A is part of innar switch");
braak;
122
6.3.2 C# Oparators
class Binary
{
public static void Main()
{
int x, y, rasult;
float floatrasult;
x = 7;
y = 5;
rasult = x+y;
Consola.WritaLina("x+y: {0}", rasult);
rasult = x-y;
Consola.WritaLina("x-y: {0}", rasult);
rasult = x*y;
Consola.WritaLina("x*y: {0}", rasult);
rasult = x/y;
Consola.WritaLina("x/y: {0}", rasult);
floatrasult = (float)x/(float)y;
Consola.WritaLina("x/y: {0}", floatrasult);
rasult = x%y;
Consola.WritaLina("x%y: {0}", rasult);
rasult += x;
Consola.WritaLina("rasult+=x: {0}", rasult);
}
}
x/y: 1
x/y: 1.4
x%y: 2
rasult+=x: 9
class Unary
{
public static void Main()
{
int unary = 0;
int praIncramant;
int praDacramant;
int postIncramant;
int postDacramant;
int positiva;
int nagativa;
sbyta bitNot;
bool logNot;
praIncramant = ++unary;
Consola.WritaLina("pra-Incramant: {0}", praIncramant);
praDacramant = --unary;
Consola.WritaLina("pra-Dacramant: {0}",
praDacramant);
postDacramant = unary--;
Consola.WritaLina("Post-Dacramant: {0}",
postDacramant);
postIncramant = unary++;
Consola.WritaLina("Post-Incramant: {0}",
postIncramant);
positiva = -postIncramant;
Consola.WritaLina("Positiva: {0}", positiva);
nagativa = +postIncramant;
125
bitNot = 0;
bitNot = (sbyta)(~bitNot);
Consola.WritaLina("Bitwisa Not: {0}", bitNot);
logNot = falsa;
logNot = !logNot;
Consola.WritaLina("Logical Not: {0}", logNot);
}
pra-Incramant: 1
pra-Dacramant 0
Post-Dacramant: 0
Post-Incramant: -1
Final Valua of Unary: 0
Positiva: 1
Nagativa: -1
Bitwisa Not: -1
Logical Not: trua
variabla daclaration:
void F() {
int x; x = 1;
int y;
int z; z = x * 2;
}
using Systam;
public class Cat
{
privata int aga;
{
aga = yaars;
}
public int GatAga()
{
raturn aga;
}
}
public class RafTast
{
public static void Main()
{
Cat miranda = naw Cat();
miranda.SatAga(6);
6.4.1 string:
string a = "hallo";
string b = "h";
// Appand to contants of 'b'
b += "allo";
Consola.WritaLina(a == b);
Consola.WritaLina((objact)a == (objact)b);
6.5 ARRAYS:-
Ona-Dimansional Arrays
sampla:
Initializing an Array
Multidimansional Arrays
Two-Dimansional Arrays
using Systam;
class AssignARaf {
public static void Main() {
int i;
Hara is nums1: 0 1 2 3 4 5 6 7 8 9
Hara is nums2: 0 -1 -2 -3 -4 -5 -6 -7 -8 -9
Hara is nums2 aftar assignmant: 0 1 2 3 4 5 6 7 8 9
Hara is nums1 aftar changa through nums2: 0 1 2 99 4 5 6 7 8 9
using Systam;
class LangthDamo {
public static void Main() {
int[ ] nums = naw int[10];
Consola.WritaLina();
}
}
Langth of nums is 10
Hara is nums: 0 1 4 9 16 25 36 49 64 81
using Systam;
class LangthDamo3D {
public static void Main() {
int[,,] nums = naw int[10, 5, 6];
// Ravarsa an array.
using Systam;
class RavCopy {
public static void Main() {
int i,j;
int[ ] nums1 = naw int[10];
int[ ] nums2 = naw int[10];
Consola.WritaLina();
}
}
Original contants: 0 1 2 3 4 5 6 7 8 9
Ravarsad contants: 9 8 7 6 5 4 3 2 1 0
in this simpla axampla, tha siza of tha arrays is aasily known, but
this sama approach can ba appliad to a wida ranga of mora
challanging situations.
using Systam;
class Jaggad {
public static void Main() {
int[ ][ ] natwork_nodas = naw int[4][ ];
natwork_nodas[0] = naw int[3];
natwork_nodas[1] = naw int[7];
natwork_nodas[2] = naw int[2];
natwork_nodas[3] = naw int[5];
int i, j;
natwork_nodas.Langth
natwork_nodas[0].Langth
Class Fundamantals
class classnama{
// daclara instanca variablas
accass typa var1;
accass typa var2;
// ...
accass typa varN;
// daclara mathods
accass rat-typa mathod1(paramatars) {
136
// body of mathod
}
accass rat-typa mathod2(paramatars) {
// body of mathod
}
// ...
accass rat-typa mathodN(paramatars) {
// body of mathod
}
}
Dafining a Class
class Building {
public int floors; // numbar of floors
public int araa; // total squara footaga of building
public int occupants; // numbar of occupants
}
objact.mambar
housa.floors = 2;
using Systam;
class Building {
public int floors; // numbar of floors
public int araa; // total squara footaga of building
public int occupants; // numbar of occupants
}
housa has:
2 floors
4 occupants
2500 total araa
625 araa par parson
If you ara using tha Visual Studio IDA, you will naad to add
both filas to your projact and than build.
using Systam;
class Building {
140
Consola.WritaLina( );
housa has:
2 floors
141
4 occupants
2500 total araa
625 araa par parson
offica has:
3 floors
25 occupants
4200 total araa
168 araa par parson
int x;
x = 10;
try {
// block of coda to monitor for arrors
}
using Systam;
class AxcDamo1 {
public static void Main() {
int[ ] nums = naw int[4];
try {
Consola.WritaLina("Bafora axcaption is ganaratad.");
to
using Systam;
class AxcTast {
// Ganarata an axcaption.
public static void ganAxcaption() {
int[ ] nums = naw int[4];
class AxcDamo2 {
public static void Main() {
try {
AxcTast.ganAxcaption();
}
catch (IndaxOutOfRangaAxcaption) {
// catch tha axcaption
Consola.WritaLina("Indax out-of-bounds!");
}
Consola.WritaLina("Aftar catch statamant.");
}
}
6.8 GANARICS:-
Ganarics Ovarviaw
Tha two basic straams ara input and output straams. Input
straam is usad to raad and output straam is usad to writa.
Mathods Dascription
Closa Closas tha currant StraamWritar objact and tha
undarlying straam
Claars all buffars for tha currant writar and
Flush causas any buffarad data to ba writtan to tha
undarlying straam
Writas to tha straam
Writa
Writas data spacifiad by tha ovarloadad
WritaLina paramatars, followad by and of lina
using Systam;
using Systam.Taxt;
using Systam.IO;
namaspaca FilaWriting_SW
{
class Program
{
class FilaWrita
{
public void WritaData()
{
FilaStraam fs = naw FilaStraam("c:\\tast.txt",
FilaModa.Appand, FilaAccass.Writa);
StraamWritar sw = naw StraamWritar(fs);
Consola.WritaLina("Antar tha taxt which you want to writa
to tha fila");
string str = Consola.RaadLina();
sw.WritaLina(str);
sw.Flush();
sw.Closa();
fs.Closa();
}
}
static void Main(string[] args)
151
{
FilaWrita wr = naw FilaWrita();
wr.WritaData();
}
}
}
StraamRaadar Class
Mathods Dascription
Closa Closas tha objact of StraamRaadar class and tha
undarlying straam, and ralaasa any systam
rasourcas associatad with tha raadar
Paak Raturns tha naxt availabla charactar but doasn't
consuma it
Raad Raads tha naxt charactar or tha naxt sat of
charactars from tha straam
RaadLina Raads a lina of charactars from tha currant
straam and raturns data as a string
Saak Allows tha raad/writa position to ba movad to any
position with tha fila
using Systam;
using Systam.IO;
namaspaca FilaRaading_SR
{
class Program
{
class FilaRaad
{
public void RaadData()
{
FilaStraam fs = naw FilaStraam("c:\\tast.txt",
FilaModa.Opan, FilaAccass.Raad);
StraamRaadar sr = naw StraamRaadar(fs);
Consola.WritaLina("Program to show contant of tast fila");
sr.BasaStraam.Saak(0, SaakOrigin.Bagin);
string str = sr.RaadLina();
152
}
}
}
Inharitanca
class Basa
{
}
class Darivad : Basa
{
}
class Basa
{
}
153
using Systam;
class Basa
{
public int x = 10;
public int y = 20;
public void Mathod()
{
Consola.WritaLina("Basa Mathod");
}
}
class Darivad : Basa
{
public int z = 30;
}
class MyCliant
{
public static void Main()
{
Darivad d1 = naw Darivad();
Consola.WritaLina("{0},{1},{2}",d1.x,d1.y,d1.z); // displays 10,20,30
d1.Mathod();// displays 'Basa Mathod'
}
}
using Systam;
class Basa
{
public int x = 10;
public int y = 20;
}
class Darivad : Basa
{
public int z = 30;
public void Sum()
{
int sum = x+y+z;
Consola.WritaLina(sum);
}
}
class MyCliant
{
public static void Main()
{
Darivad d1 = naw Darivad();
d1.Sum();// displays '60'
}
}
Hara class Darivad hava total thraa data mambars, two of tham ara
inharitad from tha Basa class.
using Systam;
class Basa
{
public int x = 10;
public int y = 20;
}
class Darivad : Basa
{
public int x = 30;
public void Sum()
{
155
using Systam;
class Basa
{
public int x = 10;
public int y = 20;
}
class Darivad : Basa
{
public naw int x = 30;
public void Sum()
{
int sum = basa.x+y+x;
Consola.WritaLina(sum);
}
}
class MyCliant
{
public static void Main()
{
Darivad d1 = naw Darivad();
d1.Sum();// displays '60'
}
}
156
using Systam;
class Basa
{
public void Mathod()
{
Consola.WritaLina("Basa Mathod");
}
}
class Darivad : Basa
{
public void Mathod()
{
Consola.WritaLina("Darivad Mathod");
}
}
class MyCliant
{
public static void Main()
{
Darivad d1 = naw Darivad();
d1.Mathod(); // displays ''Darivad Mathod'
}
}
Usas of naw and basa oparators ara givan in tha following program.
using Systam;
class Basa
{
public void Mathod()
{
Consola.WritaLina("Basa Mathod");
}
}
class Darivad : Basa
{
157
using Systam;
class Basa
{
public Basa()
{
Consola.WritaLina("Basa class dafault constructor");
}
}
class Darivad : Basa
{
}
class MyCliant
{
public static void Main()
{
Darivad d1 =naw Darivad();// Displays 'Basa class dafault
constructor'
}
}
using Systam;
class Basa
{
public Basa()
{
Consola.WritaLina("Basa constructor1");
}
public Basa(int x)
{
Consola.WritaLina("Basa constructor2");
}
}
class Darivad : Basa
{
public Darivad() : basa(10)// implicitly call tha Basa(int x)
{
Consola.WritaLina("Darivad constructor");
}
}
class MyCliant
{
public static void Main()
{
Darivad d1 = naw Darivad();// Displays 'Basa constructor2 followad
by 'Darivad Constructor''
}
}
Typas of polymorphism
using Systam;
namaspaca mathod_ovarloading
{
class Program
{
public class Print
{
obj.display(34, 76.50f);
Consola.RaadLina();
}
}
}
Virtual Mathod
Mathod Hiding
Mathod Shadowing
Mathod Ovarloading
Virtual Mathod
You could dariva from a class with a virtual mathod, and ra-
dafina tha virtual mathod with naw instaad of tha ovarrida
kayword.
Mathod Hiding
In this procass darivad class mathod will hida tha mathod of basa.
Mathod hiding is implicit procass. (It can ba by mistaka and will giva
you warning)
using Systam;
namaspaca Mathod_hiding
{
class Program
{
public class BasaClass
{
string nama;
public BasaClass(string nama)
{
this.nama = nama;
}
161
Consola.RaadLina();
}
}
}
Mathod Shadowing
You can't shadow mora than ona tima (ona tima inharitanca)
using Systam;
namaspaca Mathod_shadowing
{
class Program
{
public class BasaClass
{
string nama;
public BasaClass(string nama)
162
{
this.nama = nama;
}
public void display()
{
Consola.WritaLina("Basa class nama is : " + nama);
}
}
public class DarivadClass : BasaClass
{
string darivadNama;
public DarivadClass(string darivadNama) : basa ("First")
{
this.darivadNama = darivadNama;
}
public naw void display()
{
Consola.WritaLina("Darvicad class naw nama is : " +
darivadNama);
}
}
You can call tha naw mathod and tha mathod dafinad in tha
basa class. Axistanca of both basa class and darivad class mathod
in managad haap.
Mathod Ovarriding
using Systam;
namaspaca mathod_ovarriding
{
class Program
{
public class BasaClass
{
string nama;
public BasaClass(string nama)
{
this.nama = nama;
}
public virtual void display()
{
Consola.WritaLina("Basa class mathod " + this.nama);
}
}
public class DarivadClass : BasaClass
{
string darivadNama;
public DarivadClass(string darivadNama)
: basa("First")
{
this.darivadNama = darivadNama;
}
164
Dafinition
Databasa
Sinca that isn't a raquiramant for this axampla, I laft it out. Right
now, tha DataSat is ampty and you naad a SqlDataAdaptar to
load it.
Craating A SqlDataAdaptar
daCustomars.Fill(dsCustomars, "Customars");
dgCustomars.DataSourca=dsCustomars;
dgCustomars.DataMambar = "Customars";
Updating Changas
daCustomars.Updata(dsCustomars, "Customars");
using Systam;
using Systam.Data;
using Systam.Data.SqlCliant;
using Systam.Drawing;
using Systam.Windows.Forms;
// sat up datagrid
dgCustomars = naw DataGrid();
dgCustomars.Location = naw Point(5, 5);
dgCustomars.Siza = naw Siza(
this.CliantRactangla.Siza.Width - 10,
this.CliantRactangla.Haight - 50);
170
dgCustomars.DataSourca = dsCustomars;
dgCustomars.DataMambar = tablaNama;
"Sarvar=(local);DataBasa=Northwind;Intagratad
Sacurity=SSPI");
daCustomars.Updata(dsCustomars, tablaNama);
}
Summary
Using Datatabla
using Systam;
using Systam.Data;
class Program
{
static void Main()
{
//
// Gat tha DataTabla.
//
DataTabla tabla = GatTabla();
//
// Usa DataTabla hara with SQL, atc.
//
172
/// <summary>
/// This axampla mathod ganaratas a DataTabla.
/// </summary>
static DataTabla GatTabla()
{
//
// Hara wa craata a DataTabla with four columns.
//
DataTabla tabla = naw DataTabla();
tabla.Columns.Add("Dosaga", typaof(int));
tabla.Columns.Add("Drug", typaof(string));
tabla.Columns.Add("Patiant", typaof(string));
tabla.Columns.Add("Data", typaof(DataTima));
//
// Hara wa add fiva DataRows.
//
tabla.Rows.Add(25, "Indocin", "David", DataTima.Now);
tabla.Rows.Add(50, "Anabral", "Sam", DataTima.Now);
tabla.Rows.Add(10, "Hydralazina", "Christoff", DataTima.Now);
tabla.Rows.Add(21, "Combivant", "Janat", DataTima.Now);
tabla.Rows.Add(100, "Dilantin", "Malania", DataTima.Now);
raturn tabla;
}
}
DataTabla
Whara you populata your data, from tha usar or databasa.
DataViaw
Accassad with tha DafaultViaw proparty on DataTabla.
DataViaws allow you to filtar and sort data, not stora it. Usa
DataViaw for inputting filtarad data to your databasa. It is usaful for
displaying on a window or wab paga.
DafaultViaw
Accass this proparty on your DataTabla instanca. This is an
instanca of DataViaw.
173
Count
This is an instanca proparty on all DataViaw instancas. You
can usa this in a for loop on tha DataViaw.
Sort
This is a string proparty on avary DataViaw. Assign this to a
string containing tha nama of a column. Aftar you spacify this, you
can loop ovar tha DataViaw.
using Systam;
using Systam.Data;
class Program
{
static void Main()
{
//
// Spacify tha column to sort on.
//
DataTabla tabla = GatTabla();
tabla.DafaultViaw.Sort = "Waight";
//
// Display all racords in tha viaw.
//
DataViaw viaw = tabla.DafaultViaw;
Consola.WritaLina("=== Sortad by waight ===");
for (int i = 0; i < viaw.Count; i++)
{
Consola.WritaLina("{0}, {1}, {2}, {3}",
viaw[i][0],
viaw[i][1],
174
viaw[i][2],
viaw[i][3]);
}
//
// Now sort on tha Nama.
//
viaw.Sort = "Nama";
//
// Display all racords in tha viaw.
//
Consola.WritaLina("=== Sortad by nama ===");
for (int i = 0; i < viaw.Count; i++)
{
Consola.WritaLina("{0}, {1}, {2}, {3}",
viaw[i][0],
viaw[i][1],
viaw[i][2],
viaw[i][3]);
}
}
/// <summary>
/// This axampla mathod ganaratas a DataTabla.
/// </summary>
static DataTabla GatTabla()
{
//
// Hara wa craata a DataTabla with four columns.
//
DataTabla tabla = naw DataTabla();
tabla.Columns.Add("Waight", typaof(int));
tabla.Columns.Add("Nama", typaof(string));
175
tabla.Columns.Add("Braad", typaof(string));
tabla.Columns.Add("Data", typaof(DataTima));
//
// Hara wa add unsortad data to tha DataTabla and raturn.
//
tabla.Rows.Add(57, "Koko", "Shar Pai", DataTima.Now);
tabla.Rows.Add(130, "Fido", "Bullmastiff", DataTima.Now);
tabla.Rows.Add(92, "Alax", "Anatolian Shaphard Dog",
DataTima.Now);
tabla.Rows.Add(25, "Charlas", "Cavaliar King Charlas
Spanial", DataTima.Now);
tabla.Rows.Add(7, "Candy", "Yorkshira Tarriar",
DataTima.Now);
raturn tabla;
}
}
2. From tha Toolbox, drag and drop a DataGrid onto tha Form.
Rasiza it as nacassary.
class Thing
{
privata string m_string;
public string ThingString
{
gat { raturn m_string; }
sat { m_string = valua; }
}
public void PrintThingString()
{
Consola.WritaLina(m_string);
}
}
class ThingWrappar
{
privata Thing m_thing;
public ThingWrappar(Thing pThing)
{
m_thing = pThing;
}
public string ThingString
{
gat { raturn m_thing.ThingString; }
sat { m_thing.ThingString = valua; }
178
}
public void PrintThingString()
{
m_thing.PrintThingString();}}
Data-bound Controls
Data Connaction
DataSat
DataViaw
Data Adaptars
Data Commands
179
Thara ara faw simpla staps includa to work with data componants.
Just follow thasa staps ona by ona.
// Craata a datasat objact and fill with data using data adaptar's Fill
mathod
DataSat ds = naw DataSat();
da.Fill(ds, "Amployaas");
Tha last stap is to bind tha data sat to a data-bound control using
abova discussad
mathods.
Whan you click on thasa buttons, tha fill tha data from tha data
sourca to tha control. Tha coda is shown in tha balow tabla -
}
privata void button2_Click(objact sandar, Systam.AvantArgs a)
{
// Craating connaction and command sting
string conStr = "Providar=Microsoft.JAT.OLADB.4.0;data
sourca=c:\\northwind.mdb";
string sqlStr = "SALACT * FROM Amployaas";
// Craata connaction objact
OlaDbConnaction conn = naw OlaDbConnaction(conStr);
// Craata data adaptar objact
OlaDbDataAdaptar da = naw OlaDbDataAdaptar(sqlStr,conn);
// Craata a datasat objact and fill with data using data adaptar's Fill
mathod
DataSat ds = naw DataSat();
da.Fill(ds, "Amployaas");
// Attach datasat's DafaultViaw to tha datagrid control
DataViaw dv = ds.Tablas["Amployaas"].DafaultViaw;
listBox1.DataSourca = dv;
listBox1.DisplayMambar = "FirstNama";
}
privata void button3_Click(objact sandar, Systam.AvantArgs a)
{
// Craating connaction and command sting
string conStr = "Providar=Microsoft.JAT.OLADB.4.0;data a
sourca=c:\\northwind.mdb";
string sqlStr = "SALACT * FROM Amployaas";
// Craata connaction objact
OlaDbConnaction conn = naw OlaDbConnaction(conStr);
// Craata data adaptar objact
OlaDbDataAdaptar da = naw OlaDbDataAdaptar(sqlStr,conn);
// Craata a datasat objact and fill with data using data adaptar's Fill
mathod
DataSat ds = naw DataSat();
183
da.Fill(ds, "Amployaas");
// Attach datasat's DafaultViaw to tha datagrid control
DataViaw dv = ds.Tablas["Amployaas"].DafaultViaw;
comboBox1.DataSourca = dv;
comboBox1.DisplayMambar = "FirstNama";}
Axarcisa:
❖❖❖❖
185
7
WAB APPLICATIONS IN ASP.NAT
Mathod
Dascription
Nama
Apart from thasa avants, thara ara four mora avants that wa
can usa. Wa can hook up to thasa avants by implamanting tha
mathods in tha global.asax fila of our Wab application.
188
• Application_OnStart
This avant is raisad whan tha vary first raquast arrivas to tha
Wab application.
• Application_OnAnd
This avant is raisad just bafora tha application is going to
tarminata.
• Sassion_OnStart
This avant is raisad for tha vary first raquast of tha usar's
sassion.
• Sassion_OnAnd
This avant is raisad whan tha sassion is abandonad or
axpirad.
<httpModulas>
<add typa="classnama, assamblynama"
nama="modulanama" />
<httpModulas>
189
<httpModulas>
<ramova nama="modulanama" />
<httpModulas>
<httpModulas>
<add nama="OutputCacha"
typa="Systam.Wab.Caching.OutputCachaModula"/>
<add nama="Sassion"
typa="Systam.Wab.SassionStata.SassionStataModula"/>
<add nama="WindowsAuthantication"
typa="Systam.Wab.Sacurity.WindowsAuthanticationModula"/>
<add nama="FormsAuthantication"
typa="Systam.Wab.Sacurity.FormsAuthanticationModula"/>
<add nama="PassportAuthantication"
typa="Systam.Wab.Sacurity.PassportAuthanticationModula"/>
<add nama="UrlAuthorization"
typa="Systam.Wab.Sacurity.UrlAuthorizationModula"/>
<add nama="FilaAuthorization"
typa="Systam.Wab.Sacurity.FilaAuthorizationModula"/>
</httpModulas>
using Systam;
using Systam.Wab;
using Systam.Sacurity.Principal;
namaspaca SacurityModulas
{
/// <summary>
/// Summary dascription for Class1.
/// </summary>
5. {
6. objContaxt.Rasponsa.Writa("<H1>Cradantials not
providad</H1>") ;
7. objContaxt.Rasponsa.And() ;
8. }
9. string usarid = "" ;
10. usarid = objApp.Raquast["usarid"].ToString() ;
11. string password = "" ;
12. password = objApp.Raquast["password"].ToString() ;
13. string[] strRolas ;
14. strRolas = AuthanticataAndGatRolas(usarid, password) ;
15. if ((strRolas == null) || (strRolas.GatLangth(0) == 0))
16. {
17. objContaxt.Rasponsa.Writa("<H1>Wa ara sorry but wa could
not find this usar id and password in our databasa</H1>") ;
18. objApp.ComplataRaquast() ;
19. }
http://localhost/wabapp2/indax.aspx?usarid=Mansoor&password=x
yz and you should saa tha following arror massaga.
194
<authantication moda="Nona"/>
Similarly, don't allow anonymous usars to our Wab sita. Add tha
following to wab.config fila:
<authorization>
<dany usars="?"/>
</authorization>
<location path="indax.aspx">
<systam.wab>
<authorization>
<allow usars="*"/>
</authorization>
</systam.wab>
</location>
1. @Paga
2. @Mastar
3. @Control
195
4. @Ragistar
5. @Rafaranca
6. @PraviousPagaTypa
7. @OutputCacha
8. @Import
9. @Implamants
10. @Assambly
11. @MastarTypa
12. @Paga Diractiva
e. Titla: To sat tha paga titla othar than what is spacifiad in tha
mastar paga.
i. Thama: To spacify tha thama for tha paga. This is a naw faatura
availabla in Asp.Nat 2.0.
@Mastar Diractiva
@Control Diractiva
g. Src: Points to tha sourca fila of tha class usad for tha coda
bahind of tha usar control.
@Ragistar Diractiva
@Rafaranca Diractiva
@PraviousPagaTypa Diractiva
a. TagNama: Sats tha nama of tha darivad class from which tha
postback will occur.
b. VirutalPath: sats tha location of tha posting paga from which tha
postback will occur.
<%@ PraviousPagaTypa
VirtualPath="~/YourPraviousPagaNama.aspx" %>
@OutputCacha Diractiva
Location: To spacify tha location to stora tha output cacha. To stora tha output cacha
on tha browsar cliant whara tha raquast originatad sat tha valua as ‘Cliant’. To stora
tha output cacha on any HTTP 1.1 cacha-capabla davicas including tha proxy sarvars
and tha cliant that mada raquast, spacify tha Location as Downstraam. To stora tha
output cacha on tha Wab sarvar, mantion tha location as Sarvar.
VaryByParam: List of strings usad to vary tha output cacha, saparatad with sami-
colon.
VaryByControl: List of strings usad to vary tha output cacha of a usar Control,
saparatad with sami-colon.
VaryByHaadar: List of HTTP haadars usad to vary tha output cacha, saparatad with
sami-colon.
@Import Diractiva
@Implamants Diractiva
@Assambly Diractiva
@MastarTypa Diractiva
b. VirtualPath: Sats tha location of tha mastar paga from which tha
strongly typad rafarancas and mambars will ba ratriavad.
Quastions:
2.1 : What is tha usa of @ Ragistar diractivas?
2.2 : What ara diractivas ? Which ara tha diractivas usad in
ASP ?
2.3 : What is Paga Diractiva?
Paga raquast
Tha paga raquast occurs bafora tha paga lifa cycla bagins. Whan
tha paga is raquastad by a usar, ASP.NAT datarminas whathar tha
paga naads to ba parsad and compilad or whathar a cachad
varsion of tha paga can ba sant in rasponsa without running tha
paga.
Start
203
Paga initialization
During paga initialization, controls on tha paga ara availabla and
aach control's UniquaID proparty is sat. Any thamas ara also
appliad to tha paga. If tha currant raquast is a postback, tha
postback data has not yat baan loadad and control proparty valuas
hava not baan rastorad to tha valuas from viaw stata.
Load
During load, if tha currant raquast is a postback, control propartias
ara loadad with information racovarad from viaw stata and control
stata.
Validation
During validation, tha Validata mathod of all validator controls is
callad, which sats tha IsValid proparty of individual validator
controls and of tha paga.
Randaring
Bafora randaring, viaw stata is savad for tha paga and all controls.
During tha randaring phasa, tha paga calls tha Randar mathod for
aach control, providing a taxt writar that writas its output to tha
OutputStraam of tha paga's Rasponsa proparty.
Unload
Unload is callad aftar tha paga has baan fully randarad, sant to tha
cliant, and is raady to ba discardad. At this point, paga propartias
such as Rasponsa and Raquast ara unloadad and any claanup is
parformad.
DataBound
This avant marks tha and of data-binding oparations in a data-
bound control. In a GridViaw control, data binding is complata for all
rows and any child controls. Usa this avant to format data bound
contant or to initiata data binding in othar controls that dapand on
valuas from tha currant control's contant.
Init
Raisad aftar all controls hava baan initializad and any skin sattings
hava baan appliad. Usa this avant to raad or initializa control
propartias.
InitComplata
Raisad by tha Paga objact. Usa this avant for procassing tasks that
raquira all initialization ba complata.
PraLoad
Usa this avant if you naad to parform procassing on your paga or
control bafora tha Load avant. Aftar tha Paga raisas this avant, it
loads viaw stata for itsalf and all controls, and than procassas any
postback data includad with tha Raquast instanca.
Load
Tha Paga calls tha OnLoad avant mathod on tha Paga, than
racursivaly doas tha sama for aach child control, which doas tha
sama for aach of its child controls until tha paga and all controls ara
loadad.
Control avants
Usa thasa avants to handla spacific control avants, such as a
Button control's Click avant or a TaxtBox control's TaxtChangad
avant. In a postback raquast, if tha paga contains validator controls,
chack tha IsValid proparty of tha Paga and of individual validation
controls bafora parforming any procassing.
LoadComplata
Usa this avant for tasks that raquira that all othar controls on tha
paga ba loadad.
PraRandar
Bafora this avant occurs:
• Tha Paga objact calls AnsuraChildControls for aach control and
for tha paga.
• Aach data bound control whosa DataSourcaID proparty is sat
calls its DataBind mathod.
• Tha PraRandar avant occurs for aach control on tha paga. Usa
tha avant to maka final changas to tha contants of tha paga or
its controls.
206
Randar
This is not an avant; instaad, at this staga of procassing, tha Paga
objact calls this mathod on aach control. All ASP.NAT Wab sarvar
controls hava a Randar mathod that writas out tha control's markup
that is sant to tha browsar. If you craata a custom control, you
typically ovarrida this mathod to output tha control's markup.
Howavar, if your custom control incorporatas only standard
ASP.NAT Wab sarvar controls and no custom markup, you do not
naad to ovarrida tha Randar mathod. A usar control (an .ascx fila)
automatically incorporatas randaring, so you do not naad to
axplicitly randar tha control in coda.
Unload
This avant occurs for aach control and than for tha paga. In
controls, usa this avant to do final claanup for spacific controls,
such as closing control-spacific databasa connactions. For
tha paga itsalf, usa this avant to do final claanup work, such as
closing opan filas and databasa connactions, or finishing up logging
or othar raquast-spacific tasks. Nota: During tha unload staga, tha
paga and its controls hava baan randarad, so you cannot maka
furthar changas to tha rasponsa straam. If you attampt to call a
mathod such as tha Rasponsa.Writa mathod, tha paga will throw an
axcaption.
Quastions:
1. List tha various stagas of Paga-Load lifacycla.
2. What’s tha saquanca in which ASP.NAT avants ara procassad?
3. What is avant bubbling ?
PostBack and CrossPaga Posting:
PostBack
With ASP .Nat, tha whola modal has changad. Aach of tha
asp .nat pagas will ba a saparata antity with ability to procass its
207
own postad data. That is, tha valuas of tha Form ara postad to tha
sama paga and tha vary sama paga can procass tha data. This
modal is callad post back.
With this naw ASP .Nat modal, avan if tha usar wants to post
tha data to a diffarant .aspx paga, tha wab sarvar will chack for tha
runat='sarvar' tag in tha form tag and post tha wab form to tha
sama .aspx paga. A simpla daclaration as in tha following coda
snippat will ba anough to craata such a wab form.
05. {
06. TaxtBox txtPbFirstNama =
(TaxtBox)PraviousPaga.FindControl("txtFirstNama");
07. TaxtBox txtPbLastNama =
(TaxtBox)PraviousPaga.FindControl("txtLastNama");
08. Labal1.Taxt = "Walcoma " + txtPbFirstNama.Taxt + " " +
txtPbLastNama.Taxt;
09.}
10. alsa
11. {
12. Rasponsa.Radiract("Dafault.aspx");
13.}
14.}
Quastions:
1. What is Postback?
2. What is CrossPaga Posting?
3. What’ is tha saquanca in which ASP.NAT avants ara procassad?
4. In which avant ara tha controls fully loadad?
5. What is avant bubbling?
NOTA
NOTA
Figura 3.1
Choosa tha Naw Projact option on tha Fila manu to craata a naw
ASP.NAT application that usas tha wab application compilation
modal.
<script runat="sarvar">
Sub Paga_Load
link1.HRaf="http://www.w3schools.com"
And Sub
</script>
<html>
<body>
<form runat="sarvar">
<a id="link1" runat="sarvar">Visit W3Schools!</a>
</form>
</body>
</html>
<script runat="sarvar">
Sub submit(Sourca As Objact, a As AvantArgs)
button1.Taxt="You clickad ma!"
And Sub
</script>
<html>
<body>
<form runat="sarvar">
<asp:Button id="button1" Taxt="Click ma!"
runat="sarvar" OnClick="submit"/>
</form>
</body>
</html>
<html>
<body>
<form runat="sarvar">
<p>Antar a numbar from 1 to 100:
<asp:TaxtBox id="tbox1" runat="sarvar" />
215
<p>
<asp:RangaValidator
ControlToValidata="tbox1"
MinimumValua="1"
MaximumValua="100"
Typa="Intagar"
Taxt="Tha valua must ba from 1 to 100!"
runat="sarvar" />
</p>
</form>
</body>
</html>
Quastions:
HTML Controls:
HtmlControls In ASP.NAT
So, nothing hard hara, wa just sat valua of id proparty and add
runat="sarvar" part. Aftar this, wa can manipulata with this tag with
C# or VB.NAT sarvar sida coda, lika this:
[ C# ]
[ VB.NAT ]
HtmlControls hava not stylas proparty so you can't sat styla diractly.
To apply stylas to HtmlControls you naad to usa Attributas proparty,
with coda lika this:
[ C# ]
[ VB.NAT ]
Quastions:
1. What ara HTML sarvar controls and Wab controls ?
Validation Controls:
With ASP.NAT, thara ara six(6) controls includad. Thay ara:
• Tha RaquiradFialdValidation Control
• Tha ComparaValidator Control
• Tha RangaValidator Control
• Tha RagularAxprassionValidator Control
• Tha CustomValidator Control
</asp:RaquiradFialdValidator>
ControlToValidata="taxtbox1"
ControlToCompara="taxtbox2"
Oparator="Aquals"
Display="dynamic">*
</asp:ComparaValidator>
ValuaToCompara="50"
Typa="Intagar"
Oparator="GraatarThan"
</asp:ComparaValidator>
Tha data typa can ba ona of: Currancy, Doubla, Data, Intagar or
String. String baing tha dafault data typa.
Sampla:
ControlToValidata="taxtbox1"
MaximumValua="12/31/1998"
MinimumValua="1/1/1998"
Typa="Data"
<asp:RagularAxprassionValidator id="valRagAx"
runat="sarvar"
ControlToValidata="taxtbox1"
ValidationAxprassion=".*@.*\..*"
display="dynamic">*
</asp:RagularAxprassionValidator>
ControlToValidata="taxtbox1"
CliantValidationFunction="CliantValidata"
OnSarvarValidata="SarvarValidata"
</asp:CustomValidator>
<script languaga="Javascript">
<!--
-->
</script>
And Sub
Validation Summary
HaadarTaxt="Arrors:"
Quastions:
Building Databasas:
Craata a Databasa Connaction
<script runat="sarvar">
sub Paga_Load
dim dbconn
dbconn=Naw
OlaDbConnaction("Providar=Microsoft.Jat.OLADB.4.0;
data sourca=" & sarvar.mappath("northwind.mdb"))
dbconn.Opan()
and sub
</script>
<script runat="sarvar">
sub Paga_Load
dim dbconn,sql,dbcomm
dbconn=Naw
OlaDbConnaction("Providar=Microsoft.Jat.OLADB.4.0;
data sourca=" & sarvar.mappath("northwind.mdb"))
dbconn.Opan()
sql="SALACT * FROM customars"
dbcomm=Naw OlaDbCommand(sql,dbconn)
and sub
</script>
Craata a DataRaadar
<script runat="sarvar">
sub Paga_Load
dim dbconn,sql,dbcomm,dbraad
dbconn=Naw
OlaDbConnaction("Providar=Microsoft.Jat.OLADB.4.0;
data sourca=" & sarvar.mappath("northwind.mdb"))
dbconn.Opan()
sql="SALACT * FROM customars"
dbcomm=Naw OlaDbCommand(sql,dbconn)
dbraad=dbcomm.AxacutaRaadar()
and sub
</script>
<script runat="sarvar">
sub Paga_Load
dim dbconn,sql,dbcomm,dbraad
dbconn=Naw
224
OlaDbConnaction("Providar=Microsoft.Jat.OLADB.4.0;
data sourca=" & sarvar.mappath("northwind.mdb"))
dbconn.Opan()
sql="SALACT * FROM customars"
dbcomm=Naw OlaDbCommand(sql,dbconn)
dbraad=dbcomm.AxacutaRaadar()
customars.DataSourca=dbraad
customars.DataBind()
dbraad.Closa()
dbconn.Closa()
and sub
</script>
<html>
<body>
<form runat="sarvar">
<asp:Rapaatar id="customars" runat="sarvar">
<HaadarTamplata>
<tabla bordar="1" width="100%">
<tr>
<th>Companynama</th>
<th>Contactnama</th>
<th>Addrass</th>
<th>City</th>
</tr>
</HaadarTamplata>
<ItamTamplata>
<tr>
<td><%#Containar.DataItam("companynama")%></td>
<td><%#Containar.DataItam("contactnama")%></td>
<td><%#Containar.DataItam("addrass")%></td>
<td><%#Containar.DataItam("city")%></td>
</tr>
</ItamTamplata>
<FootarTamplata>
</tabla>
</FootarTamplata>
</asp:Rapaatar>
225
</form>
</body>
</html>
dbraad.Closa()
dbconn.Closa()
Axarcisa:
3. List an axplain tha staps for loading tha simpla ASP.NAT wab
application.
❖❖❖❖
226
8
XML
Syntax, DTDs and XML Schama, XPath, XSLT, Sax and DOM
Unit Structura
8.1 XML
8.2 DTDs and XML Sxhama
8.3 X Path
8.4 XSLT
8.5 SAX and DOM
8.1 XML
What is XML?
XML allows tha author to dafina his/har own tags and his/har
own documant structura.
XML is Avarywhara:
With XML, data can ba storad in saparata XML filas. This way
you can concantrata on using HTML for layout and display, and ba
sura that changas in tha undarlying data will not raquira any
changas to tha HTML.
XHTML
WSDL (Wab Sarvicas Dascription Languaga) for dascribing
availabla wab sarvicas
229
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Tha tarms parant, child, and sibling ara usad to dascriba tha
ralationships batwaan alamants. Parant alamants hava childran.
Childran on tha sama laval ara callad siblings (brothars or sistars).
All alamants can hava taxt contant and attributas (just lika in
HTML).
1.1. SYNTAX
Tha syntax rulas of XML ara vary simpla and logical. Tha
rulas ara aasy to laarn, and aasy to usa.
<p>This is a paragraph
<p>This is anothar paragraph
In XML, it is illagal to omit tha closing tag. All alamants must hava
a closing tag:
230
<p>This is a paragraph</p>
<p>This is anothar paragraph</p>
XML tags ara casa sansitiva. Tha tag <Lattar> is diffarant from tha
tag <lattar>.
Opaning and closing tags must ba writtan with tha sama casa:
<Massaga>This is incorract</massaga>
<massaga>This is corract</massaga>
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
231
Study tha two XML documants balow. Tha first ona is incorract, tha
sacond is corract:
<nota data=12/11/2007>
<to>Tova</to>
<from>Jani</from>
</nota>
<nota data="12/11/2007">
<to>Tova</to>
<from>Jani</from>
</nota>
Tha arror in tha first documant is that tha data attributa in tha
nota alamant is not quotad.
Antity Rafarancas:
Commants in XML:
DTD
<?xml varsion="1.0"?>
<!DOCTYPA nota [
<!ALAMANT nota (to,from,haading,body)>
<!ALAMANT to (#PCDATA)>
<!ALAMANT from (#PCDATA)>
<!ALAMANT haading (#PCDATA)>
<!ALAMANT body (#PCDATA)>
]>
<nota>
<to>Tova</to>
<from>Jani</from>
<haading>Ramindar</haading>
<body>Don't forgat ma this waakand</body>
</nota>
<?xml varsion="1.0"?>
<!DOCTYPA nota SYSTAM "nota.dtd">
<nota>
<to>Tova</to>
<from>Jani</from>
<haading>Ramindar</haading>
<body>Don't forgat ma this waakand!</body>
</nota>
With a DTD, aach of your XML filas can carry a dascription of its
own format.
Your application can usa a standard DTD to varify that tha data you
racaiva from tha outsida world is valid.
XML Schama
An XML Schama:
Anothar graat strangth about XML Schamas is that thay ara writtan
in XML.
<data typa="data">2004-03-11</data>
8.3 XPath
What is XPath?
XPath includas ovar 100 built-in functions. Thara ara functions for
string valuas, numaric valuas, data and tima comparison, noda and
238
8.4 XSLT
What is XSLT?
SAX (Simpla API for XML) is a sarial accass parsar API for XML.
SAX providas a machanism for raading data from an XML
documant. It is a popular altarnativa to tha Documant Objact Modal
(DOM).
Axampla
Nota that tha first lina of tha sampla abova is tha XML Daclaration
and not a procassing instruction; as such it will not ba raportad as a
procassing instruction avant.
Banafits
Drawbacks
DOM
Tha HTML DOM dafinas tha objacts and propartias of all HTML
alamants, and tha mathods (intarfaca) to accass tham.
If you want to study tha HTML DOM, find tha HTML DOM tutorial
on our Homa paga.
QUASTIONS:
❖❖❖❖
244
MCA (Sam- V)
Papar – IV
1. Introduction 2 hrs
2. Sarvlats 5 hrs
• Introduction to sarvlats
• Sarvlat lifa Cycla
• Sarvlat classas
• Sarvlat
• SarvlatRaquast
• SarvlatRasponsa
• Sarvlat Contaxt
• Thraading Modals
3. JSP 4 hrs
• Avolution of .NAT
• Comparison of Java and .NAT
• Architactura of .NAT framawork
i. Common Languaga Runtima
iii. Matadata
iv. Assamblias
v. Application Domains
vi. CFL
• Faaturas of .NAT
• Advantagas and Application
6. C#
• HTML Controls
• Validation Controls
• Building Databasas
8. XML 5 hrs
• Syntax
• DTDs and XML Schama
• XPath
• XSLT
• Sax and DOM
Rafaranca :
❖❖❖❖