0% found this document useful (0 votes)
2 views

Java

The document outlines various programming concepts related to servlets and web applications, including handling HTTP requests and responses, form submissions, and session management. It provides code examples for creating simple servlets for operations like addition and subtraction, user login, and registration forms. Additionally, it discusses the use of cookies and the importance of maintaining session state in web applications.

Uploaded by

kaushikboss0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java

The document outlines various programming concepts related to servlets and web applications, including handling HTTP requests and responses, form submissions, and session management. It provides code examples for creating simple servlets for operations like addition and subtraction, user login, and registration forms. Additionally, it discusses the use of cookies and the importance of maintaining session state in web applications.

Uploaded by

kaushikboss0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

R. E. Society's Roll No.

:ITA-30_Class:YB
R.P. Gogate College of Arts &Science DateExperiment No.:.
and R. V. Jogalekar College of Commerce,
Semester .Signature
(AUTONOMOUS) Ratnagiri.
DEPARTMENT OF INFORMATION TECHNOLOGY

Aim/Tile: 1oplmn ts the fal loing Simpe


s e l t yrcat ion
Sert
. Servts aree jovoa progrQms that ruDS
04liatian serer
Åacts as a middle laye between equst
Coming from wecb brouser
Htt|clients & database s on application
on thne HTIP SrVer Thy or used to
ex tend the capabties Ota Seruer
hy handhag quest
dynamic contentsuh os HTMLpogs
-To the contet of servlet web asnl
tion
Concapt mlatd to handding forg
Shssian ¶ bttp reques ts
|Atlan
Theoct1on attibute n an html dar
edines the wRL to which the darm dat
wL he suhmitted.
-ALhen the ues su bmtstheforn
th data ls sent to the sever at

<6orm octian -" submitem")


Q mthad
The methad atti hute tn an HTOL foLe
speusies bow the data ls sent to
the seryerhese aree two mthods

is apndnd to th VRL as a
guey para ten
Tynlcolly usd doY netu ing data
talung
posT:
-JDato is ssnt In the
oequest
Typlcaly usro dor hod& Hrre
Sor SuDmittin the
data that changs ths!
(itoting state on the
The datais nat \S)
maling
sar snSte dota
SecUe than GET

a Creote o sirnple
using
Program
a serlat
0uplicotan
indxhtrml
2100CTYPE htm
Lhtm>
<heod <Whegd)
<bady
KEarro mithad ='Get" oct iancal
<input type"numbx
ploabalder Énty humhe

<input tyse =" humbr


plahg lde"Enter nunhe

br Lh nome=nm2
<label odd, ion'Addetran
</labd
input
Substraction tye"koda
yalueSub
<in)ut type" rodio" wolueDiv"

mytphcotin
<inyut tynes rodig " uolue "mwt"
-"calcwate'"
<inpwt type"subrot" walue<" coleulate
<inpt tye =l eset" Volue"Rs"
<láorm
<lhody
cal jova
pockag caleulator

inpeYt jovaX- servlet.


Smport jvox sevet. http*

public class cal ex tends HAtp Strvlet


orotected void do Get CHttp SevetReues

thrauws SevletEx ptíarnTOÊXCep tion

piot ALite 0ut respopSe: qt nlritet):


try
trin ouohl equst-qtPoremneter
("Dum!"

Sting
String apreguat qet Poromter
CCalclate)
dable numbwll 3 Dauble porseDoub
(numb )
L8 Copr' eqals ("Add")

3
Qut: Hntln (numbrl
-LhpourmSeJbaub)u
else i Copr equals sub'))
Outntln Coum besll
numhurn
println (num bell humhuria)
olse idCapr. ec uals(lti))

else
utpinto(numb nclnumbur
O4pin tlnEnted Tnaud
pintln"Entrd
coth(Excn tian e)
Qut println (Errar
Iode htmt

-ox
i5lununbr
Additlon
Diuls lon 0 mwtphcoton o
Colcuo
Cocote a selet
b] the Usrnomee
Sor ogin poge
then it_Soys essog
misso

prograr
in dex:htm
<\D0cPE HTML)
htm)
heod)<heod)
<bo dy
Kform ation =
action"lo4
<hl) Lagin farmn hl)
<input type "text
ploaho ldur userno!
"usernome" <bri
Kiput type : 'possword
plachader "posswor d"
home n0sS ward"br)L
<1&ormn)
<lbodys
lhtrol

podkog lagini
import j9va i0-*j
Smprt jovox Servut *j
Impart joyox SUrvut .http
publa doss log utunds HAtpS
proteed Vord AroeSsRequet do

HttpSuvutRquest
equest Httpser
Resane espanse)
+hrows StowletExeentLa TO£xce2ts
PrintHter out respane qetnit
tye
String unome eqaistqetPoromt.ex
(usurnom
Stving passard niquestqut Porory
ter ("possward")

osswrd. equols(" 1n34"))


Qut pintln " Hll"

Outprintln (" log!n doil"


dakd

outrn tln (Error "t4tmesst

Output

LoaN Form
dnine

as344ST d

totn
qCste a caístratiao soav let in íovo
Using TDBC. Accapt the detols
using
htmlfarm & stare the gstationd
deta ls ín deltabosc

Proqrom
) SQLconnection/uey
use dor-proctiols
>crea te tobe aqistrat'ao
uSrnome vorchar (30)
osswr

vorchor (3o))
count
iDdex htol
<LDoCTYDE HTmL)
<htm)>
2heod)< heod
<body
Lhl>2egstra tian Farm <Lhl>
Kform action=lrg methad''get"
<ipput t p e t u t
plocehaldes 'usemnme!
nom "usrnome ( leited
<hr) <br>
<Inpat typeposs M0rd"
p loceha des "Dosswrd
hame
<h <br
type ema"
pla aldta "emL

<br<br
<iDput Lypstet"
ploch ldur

<hr br) county eud,


"Registe' yol
<input bye"ret
<Láorm>
<lboay
<htmn

import javo sgd *j


Import jovax Srv t*j
Impor jovox Serethttn*j
publlaless a etends Http Sery let
ovrríde
proteed void
equest , Http
dact CHttp Stnvletkae
EhrowS Serlet ion,
Rapansee
SrywtE xcapt IOExcpti

chorsete "))
Pint\Nnte out =espn
ty
Sting wnomez equest gtloronmt
String posswd =quest gctarane
C"Possuord ")
e (Chnphintln aut
CExcaptlon
e) catch ?
dlly "succers insatcd
rouIosatd
exe pr jnt
cauntgl ysetsting
(4,
rcststrng
passwd sstung
(2 rr
(IuemeprestStr1ng
") walus Countng
rat into("insnt Statemnnt
por PrpoYdStatmnt
con: pe
"YOot1924r"
icols Idor- 0G
calhast
33 1/llo
(jdbcConneton
gtrgu
Cannton
con=
ot untyuest
get Sting
tr eroole
Sting
blc loss edame en tends HAApser

yrotected wojd do kut CHtp SeavtRegu


LgucstHtpSonvltRespoose spaosc
throws ServutxcptiaIOEyceptiod
Paunt\te oLt mespaDse qtwt

Stng unom= equ<st . qt Poror


Out ntln (" \Nllcorm to
pog, deo+unom ny
Catch (Ex cp tion e
Ot.
piotln ("Error "gtmug

Out put:

Logn or m

Log
\NI'lcont jova

dor
admin
nurmber o£
to stothe
Useohosis tcd

They iodarnatiooe
client
multiple nomea
btwen hos_a
- H
cOolk ottribute Su
damu
acommentpatfh ý
as
Veaslon numbeo Considiod
equest
dedout eoch teehnin.
reduestTo eaokes
a new
eadd ctor
sevet So the caokeg s
the browseoAdtsr that I
cotche ad
Yq s Snd hy the USa Cooks isk
oddd hy gues t by dedat Th
2ecog nid theus eor s ald uw

Progrom
Jndex btml

<htm>
<heod hea
<body
<doxrn otion "Pag
ntr yaur Nare
<input tynetxt"
hame tenta
Linpt yncsuh m1t"
volue="dk ntey!
<dorm
</hhm|
Pagel java

ubl closs Pagl ex tends HAApSerult

proteted waid doGt CHttp Seay letRegu


Rst equst, HttpSa letResponsc
mespon se) thrQws
&Qtseov0etEYaptian,ToExptiorn
espse. setContnt Type ("text/h tml

2rintHteaut = esponseqtNriter
out pntlnc"shtml><h«od><tite
Pogalth <heod>):
Outrín Hh (1< bady hacolar =pnk y"
Stng nonez e questqt Poremete
(textNam
0 u t i n tro cl<h> Mecanc'tunoet

Cookiekez ne
esonss add Caalxie Cclk )
tespanseodd Casle Colel
("<ht <a heta Poc2)
utnniot o Poye 2 <lo </hJ
Clhck to ust
4ath("<lhody "
2untn("4|html, ")
3

Pog 2ovo
Pocko mypaki
n p t fovoX s r t

etnd
sHAtpSerlsi
pubhe closs poge)
overude doart CHAtpsruut
protected void
Regust equsstHEtpSavtRo

thras " texthto!


response setCantntType
Chorset UTE -& ;

outpntln C <html <hhod) ttl


Pag<lttes heod");
out pintln ('<hady bqcalor s ylls
Cookie cka aagucst qet Cooleits
dox Cint i= 0 k ck.length
-Qquals

int count Intege


Dut prí ntlnh> VISLt
Caotele
toStung (caun
Tsponst. add Coalsie
t))
olse itCckCi]qtNonelequals (

Hntln("<p Uscnore=t

getse
Outnatin C"bl) nelcorre,
&st time 3)tor

Cootie ('vst",);
esponst, addaskies (nwllsit Cookie);
owt_prntln (<p) usenom unknau

aut ntln C" <lbady <lhtml":


3

Gutpt:

Enter you artAthor

chde to entr
ALelcamue AthorN

\7sIt No

frcsh usernme eAAho


aCreate a S letdemons trot the
lso chek wh hen theuser has
VISitsd this 4ag
n0 dst tme or hos
also

o nurober of robun that


Sram fot thot htto is
fs the
Stotless )ro toco|
H¥Ap Ses)an abyet is used to stare
ntre sess0on wth ospeudia client
att bute frorn bttp
bttp seesiao objet
Aoy Scavut con hove access to
HttpSess lar abjet thraughout the
ahieet.

Prgram
Ines htn
<Do cTYPE HTnL
<html
<hegcd>
<lhesd
<ba dy
<dormn actlOn 'Dag methad"gt"
Shput typ Eent
ne = t N a m < b r

<Iht rmn
Dogjdua
patog nyocki
danotjovoio*

mport ovoxset httptoj

pbc clossPog eA tends


ovende Httpstal.
pro teted voLd doet+
request HttpSAN CHttp SovtRe
blesponsO reDor
throuws SerN
Senv utEy
utEx cp
cep
tianI0Excunt.
espanse, setCan tutype(" toxt!hte
chorset<u TE -R")
OutrÍntn Ch<html> <hhad<tt
Servt 20g <ttle> <huod
HEtn Sessian hs= eguet qet Sess loo
(truc
dut println l<bo dy
bcalor'y
stng
hs
hameE Gquest qtParanm
setAttbutu ("unome
hsstAttbute C"ysLt," nam
OutrintLn C<h neleo
tme </h ";
lse

Poase Lnt
bs qtAtta'bute, Cyist))H
outpintl (<h) vou ols kt d <lh"S
hsst AtA but. Cysi!
?
Outinln"Kh Your Sess190 ID
hs.qutTd ) "<|h ")
awkrntn <hlYau logscd inat"+
new jovowtl DoteChs get Creation
auty n tln (<hl <a hred= Pogel
Cliclefon pog <a> <|hS)
out pintn ("<hls <a hre logautSen ut
S CLclk
toTornoinate,
Sesslon <la
Ot pin t h (" <lba dy <lhtm )

podkog mypo dej


Serrv t *
Jmport (ovo X Sersy ut http j

ablc loss Pogc2 a tnds HtpS e t

GovrrLde
proteete d vard docet (Htp StautRequst
equest, Http SeryetRex2ongo ripans
throws
Rsponsest Content I4pe teat/htm
Paintu be out esponsc q t l iter
Out prinlacl<html>hedLts
Httpslun hs qucstqtSesS1an
Coalse
otpnntln (1<h welcome agoío on
Pog No.0<hls")
int visttotegta pdsTnt
hsqtA+tnbute Cly((Strn
OutpnthC"b) Vou Vsitedtysk
hs "Tme"h");
setAAtrbute ("
tpntln (" <h> VISLt",4vIs1t);
YourSessioo
+hs. gttd +" <bl) ) TO!
Ot ntln (^<his You
lagged(hsin at
t new Jouo.ut lDote
Creatian
OLtpnth c'" <hl Tim)+
<o "el) "))
hrd -Pol
Qutrintln (<hl <a hreda LogatSent
Session <

Qt puntIn (ba dy> ")


Qut pnth(hami")

LogoutS
po cko
eryutiova
myoc
impart jovo io-*
mport ouX Seuk.s
impot pyo X Seavut
hthpti
closs Logaut Seuwt ex tends HHp
pro teedd old docrtCHLLpseeu et Requst
requs t HttpSavt Respanje riponsc)
Seav Excyptlào TOExptian
esponscsetCantnt Tune ("htrnl|teat
chorsteuI¾-8)
Outpntln ("<html> heod) <tt
Scayut Logaat Scat Jtitl
/ovoX Semwlet hthp HAp Sessidns

a t how Kh>! Loggd

Out

UscxtDLALhoy-c

Pecetstmt
our SessonO s400 3 2054G92102id

3S2

Clickfor tinnonotte Sesda

You might also like