0 ratings0% found this document useful (0 votes) 83 views20 pagesEJ Practical
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Bim & Using Reque spatcherr Interface Geati a
Servlet which will validate the password entered
My the _user ) iF user has entered —" Servier” as
Password 5 »then he will be frworded to Another
!
| rw pages else he User will Stay on Same index:
a poge Aan esr messoge wilt be displayed -
E packoges used 2 :
{
ova- lang
java: fo
jovax: Servut . http
®
O_j
@ jovax- sewlet
©
® Demo
Class used §
© Printer iter
® To Exception
© Shing = a
6 0b; ed - a ae
© Hips
o Serv ur xception. . Denne CeTnierFace used inet
© servletRequest”
Q® ServletRes ponse
Hip Sew Request”
@® Hip Serv wr Response
© Requer Di pachor _—_|t_defines_an_objecr Hat
From the Client and Sends them
receives Hquests
Ap anyweb Ksource ( HIML) JSPs Sew ere) of the
Serves + The Servur Containers Cheatis the Request Dis -
pakches object , Which used as Wrapper ty Serves
lesource —_Lacatadl at a particule path oF Given by
pothiculas name:
Methods used 3
@ void _ processRequest Ciitp ServtuRequeste request >
“ T
itp SewletKesponse__ besponse
@® Shing _qerserver En fo C)
@_ public Shing nek Context Path C)
@ yoid _setConkarTy pe CString” 44 pe)
© PrintWriter qerwritie_O:
@ Wid _prinkln ~(ctring 5)
@ Shin _ JetRovam dem (Shing name >
® doGer (HiipSenilatRequest __Fequest_» HtppServur Re sponse
sponse ) +
@ Void _dofost (Http SelerRequesté quest >i senlek—
Response _Sponse )© Shing _getfavameter (Shing, EE)
© boolean “equ Object a
erRequestDispakhes (String path J:
(© Request Dispalches q
— Lt lehirns a Re ues t Dispatcher objec that “ads
as A wrappes for the Kesource locatid’ ak the given
path + The Request Dispatches objeck Can be Used “to
or to include
Fincord a Hequest to the source
Can be
the tesource ina Ksponse «The _kesource
dynamic or Stalfc:
void
uest bequest _» SerutResponse ks pone )- -
© forward (SenrRe
— This methed “forwords a kequese’ fom a SévGr
on the
to anothers psource ( Servier» Tsp, KTML)
[+ allods one Servet to do Prliminary Process~
Ceres +
jing of a Request and ancthes Ht source po qenesale
Response: ‘
@ Void include ca SenvlitReq ust ese 2 ServlatRespo nse
sponse I+ Includes Gnkar oF a
Resource (itTmL > Sewlur , Tsp a ‘inthe kes ponse-
This muthed enables preqrammatic Crver —side jncludles
o
Ki| Aim ¢ Create a Servet that uses Cookie te Stole the
numbes of times a uses has visited Servet
Packages used 8
© | java: lang
© jaye ite)
© yavax: + Servlet
® “vax servlet» http ,
| © Demo
Class_used §
© PrintWrite
@ LOException
® Shing
© HepSevuk
© Serv Exception
© Objece
@_Gekie — !4 ts a Small amount oF Information
Sear by a Serve te a web-brmwser > Saved by the
brovres” and Lali sent” back tthe Serven . A !Gokie's
value Go Uniquely identify a Client » So Gokies at
Geemenonty used For £5100 Maa ar
FOR EDUCATIONAL Use,4 siege value and optional
aktributss such as A Gmmel
A_Gookie _has_a names » path Qod domain
a version numbers:
TA imum age
qual fiers 2» _maximuy 4 2
ThlerFace used $
© CervlerRequest-
® Gervlut Res pone
@ Htprvt Request
® Hp Serv wr Res ponse
\
mathods used 8
|
| @ Void _processRequest (Hip Server Request equest™ >
HitpServie Response sponse
(®_Shing _qerServer Inf C
ublic_ching _getConkex tPath Rehirns the portion
oF the Hequsst URE that indicates the Gntext of
jhe Hequest_ + The path _strle With a" /" Charadlor
@ void _serGonkwType (Shing type)
@ Priarw rite erwritin CD 4
|©_ void println ( Sting 3) u
I@ Shing getParamwtes (Shing name) 4
|@©_do Gar HitpserviukRequest. Fequest 9 HttpServletResponse ——
sponse) - = b a
evold de Post ( AttpServlerRequest vast » HHpSewlthes- —
Ponse sponse ) re 4 *4 2 *P =
FOR EDUCATIONAL USE| @ state String valueOF (int 1) — Tr jehirns the i
| Sting _ttpissenkeiben of “the int arqumenk . “(he rece nk =
ation fs exachy the one thirned the Tnkegers «
LteString rrathed, of one argument J a
i rq ure
_|@ void _addCookie (Cookie _ Cookie) — It adds the
¢ peciied Cookie te the kesponse + This mukhod Cao
[be Calted mmuttiple __times_ to Sek mo than one
| Cookies
|
|
1
I
TW® _oekie _ guess On
| Garaining al of Ane Cookie object? the client Sent
| yoith Yhis vequest This mathod rehurns null fF no
| Cookies were _ Senk-
aname 0) —— Rehims tw Name oF the
| Gokie > The name Cannot be Changed afks Ceation-
[
[@_ Shing _getValue Crels the Cusrent value oF
|) this Cockle:
(GS Static lat parsel.at CString 3)
|
Iro Static Sing valuedf (int 1) — Tt jetwns the
| String iesentethon of “the ink argument . The Hprerent-
ation fs exacHy the one thurned Y the Totegerss
ae String Faned| of one argument» 7
ans a
\
@ void addCookie (Cookie Cookie) —— I+ adds +he
peciied Cookie +> the |esponse + This rathod Can
be Called muttiple times tp sek” mot than one
Cookie:
®@_cookie C7 qerCookies Cc) ——_It_tehirns_an_aroray
Coataining all of the Cookie object? the Client Sent
with nis yequast: This outhod rehirns null fF no
Cookies were Senk-
erName C) —— Rehirns the Mame of the
Gokie = The name Cannot be Changed @fkx Ceation-
® String getValue C) — Grels the “Cusrent value oF
this Cookie:
©@_Staie tne passedar CC ng 8)
FOR EDUCATIONAL USE.[ Peach cal 2c
Aim @ CGeati a Servlet demonstrating the use OF
Session Grtakion And deshuction « Algo Check whether
the uses has visited this poge First’ time or has
Nisited eorlies also Using cessiong -
=
packages used §
pees ee
© java: lang
7
i
| ® jave-to
®_jJavax + Servlet
@ _javax » Sérulk. http
| © Demo
© _jovo-uti] —— This packoqe Contains the Gollechons
Frome®ork > Collection of Claris ,event model , dale ,
time Facilities and util Claspeé etc:
Classes used §
@ Prinkwriter
® LOException
@_Shing
@® Object
© SUF EKception
FOR EDUCATIONAL USE|
I
ff
|_ © pera g
I_@D —= The _java-util Date “Class _eprients dala
[and ae in jevar Tr prides Gooshuctors and matheds
| to deal with “det and time in _javo--with milliscceond
; J
i Precision
|| Thtesface used %
|
l@ Sere Request
I © Seniuk Response
Http SewurRequest
‘® Http SevvleFResponse
2 Request Dis parch ers
HitpSession — __ The _jntesface Provider a woy +
| ae a uses caress mor than one Page request
|_Or visit to a web ote and Shoe information
| abour the user. :
I+ allows Serv lat to view & mani putecte \nfrmation
test 2 Sesion and Bind Objects A Sessions ratlowing
{User _in formation ersist CNS MULH ple
| Goonectians: f o- e ses
fratheds -
| © void procew Rea SEC Hilp Servier Req uest= quest >
Http Serviek Response Hes ponse > 4
f
=) FOR EnerGQ)
Banter
® String getServetEnfo C)
g void serConkentTy p e (String type)
| Shin getCookeet Fath ©
© ae geeWri ler ¢)
© void _printta (Shing 5)
_@ Sting gerParamitio™ (Shing name )
© deGe (itipServturrequese yequest 5 Http Servlat” Res pone
sponse >)
@) dofost (_HtipSerler Request request 5 Hitpservlet Reg ponse
Hsponse »)
@ _tWttpSession getSession (boolean Geale ) —— Rehirns
| the Gurren PaipSessi on associated) with this quest >
Lor if thee is no Cwwrent Session and Crate is hue,
| Rhirns Q new Session’ LE Crate is false & the
Kequest has ne valid HtpSession , this method rhirng
yuu 7
[o)
|
FOR EDUCATIONAL USE I|
ff
I
>
®
Prochical 4a.
|_Aim 4 Develop a_Simple JSP appticakion to dis play Value
[obtained feomn the Use OF inkinstc objects ‘oF Various
type «
| °
Packages used 3
© java- lang
@ java Sewer
® Java. Servlak-hitp
J
Classes used
© Object
@ Print rite
@_HipServut-
Interface used $
@_ Servis Request
® Server Response
@ Ht Servier Request
@_HipServurRequest:
® HitpSerrion
FOR EDUCATIONAL USEMethods used &
é
@ Shing getMethod ©) —— !* kehirns the name of the
HTTP rAttod yor Which this Fequest yoas made e4-
GET, PLT 5 Post - :
@ Sting ger Query Shing © —— _Renrns the query shag
thar is Contained’ n> the Yequast URL afte the path -
TWs wil Rhire NULL TF the URL doen't have a query
|_Sting. f
@ Shing _gerContetPathO
® Shing _gerRequast REC) —— Ruturns the part of this
Lyequest's” URE From the protocol name _up to the Swsy
Shing in dhe First line of the Tre Kqust iQ
+ —+
i © Sting gerPathT if O—— Returns any extra path in Form -
alion asrotiatid with the RL the Clie Cent When tt
mode this request: Thetitra path information fUows the
| Serv le Path but precedes the Query Shing and States
with a" /" character i ~
@_ ink quStatus () —— I+ gets the Curent” status
Code oF “this Hsponce. e-q-
+ 100-199 8 Unformational Hs ponses
+ 200-299 8 Successful _ sponses
+ 300- 353 3 Reditection messages
1 too7u9g_¢ Client rns Ks ponses
Geesas) )
+ $00 - 599 Servers SHIRES ESE ATES \ 352
ESD
2 Returns the Ochuad
Fes Side used for_-the kesPonce . 1G No _ buffing
[3s used »this WiU tehiro oO.
® void SetG@ntentTy pe (Shing type)
SSS okey HD
@_int hashCode oO Rehuns the hash Code
Value fr the objec on Gling
It turns 4 bykes
Value db hoshiag algorithm .
— Geel T = :
© Shing qutd CO)
Os getNlaxTnactive Interval Cy) ——— (+ turns the
Maximum ime interval, in seconds that the Cerve=
Gataines wit keep this Sesion Open behoeen Chienl—
Gccerses « Afles this lnteval y the ‘Servier Gataines wil
‘nvalidats the Sesion. —s
© Log guration tine O
© Long getLast Accessed Time Oo iE
BeS
Practical +b
“Tim? Develop 0 Simple Js
P_ application To pass values
‘te anothers with validations (Name ~
fiom ONC _ pas
as hobbies — Checkbox emai l-txt gendess -
J
hat 2 9e =
padi bulton)
Packages used 6
@ java: lang
@_java:to
® Java servlet
@® avery hit
Classes used &
® pais rit
@_String
O TspWritir
@ Obyedt
Thterfaces used %
Servlet Req vest
® cerulakResponse
(A _HttpServlarRequest
© itpSewlakResponse|
I
fn Methods _used 8
| @ boolean validate (HifpServlu Request: veg vest 5 TspWritinr
[out) — This _muthod fs usedy detined mathod used
te validate differnt fields such as Textfeld j textbox »
Checkbox etc:
@ isEmpty —_ boolean is Empty 0
Oe Shing =gitteraptin (Shing Name )
®~ Shing” CY getpfametirr Valives (String name)
6) privdTn —__ Void Print (Shing)&
|
Prac. 4c]
Aim ® Crate a teqistration and login
Tse application
te _teqister and aiuthenticat: the user
based on, ausernam
Gnd “passtord using JDBC
Package Used &
as
java: lang
javas 40
Java » Servlet
C®LCBE
oS
: init
ava + Servers
java “S41
im
lasses used 2
© Printwrites WA
@ Sting a
@_Objed
® HitpServlk-
© Drives Managers
© CLatexception
Interface used 3
CD ServitRequest-
OR LtResponse
Gonnection
® Stetenent—a
Method used ©
D_ Void prvcers Request (Http Servlur Request sdeq rest»
T t
Hit Servlet Response response )
@® bid _printto( Sings)
& Static Conneckion” gerConn ection (Skiing us! Shing Usernary
Shing password )
@® Shing qetfrometin- (Shing _s)
@® Statimeak Create Stafanon CD
6 int execuileUp datte (Steng sql)
@ Pr paredStatement “prepare Statement (String query)
© _seSving — youd - setShring Cine Passamaten’ndex >
Shing x)
© Seis ring Cint > Shing)
|
|67
ee rene
a Practical 3a
“Rim 2 Cea a Servlet application to uplood and
Aownlood 2 Gle-
“package used 2
t
©® javario
@_ javax -Sevler
@ Javoxs Servlets http
@) jovax Servt- annotation —~ |t Gatains num bes
of annotations thak allows user te use _annotakiens
to _dedar Servut , Filters » Listeners A motadata for the
dedard Gonponont -
Class used 8
Shing
Q@ Objeck
© File — [+ is an abstyact prsentation of File
and lireclyry _pathnames + sew lnkrfaces 4 OS use
Suslem -dependent pathname Strings te _name Ailes and
dlirecbories ‘ a
[@ FienotfoundExeeption —— [+ Signals that an attempt
“to open the Glo ‘denotid by a spedfed pathname has
aud v 1 t
FOR EDUCATIONAL USE,oq
Lae
ee
|G FileOutputSteam — It _is_an ouput Stream foe _ wri tin
—T| dda _te a Ble or Bo Tea J
pol
—T © Io Exception
TPO TnputStream — “This is_abstrack clase ond Superclos of
alt the Classes Fepresenting as) _inputsheam of bytes
“J { t
® OutputSheam — This _abstrack class Fs_Superclass of oll
Clases rpisenting cutpurShtam oF by tes
© Pinkwriters
ServlakException
@ Hitpservlke
Annotakion —
@Multipart Gohg — lt may be Speed 09 Servlet
Class indicating thal instances of the Serle expect
Hequest that Conform to the rmulkipasrt_ [For acta Mime
Type:
Pe
Thierface_used %
© Sewlek Request
® Sew Response
n Senllut Req yest
® HitpSerr Res pose E
Ie Pare —— This represents a part or form item that
— [was ieceived within _routtipas€ | form-date Post request:
ay FOR HBUCATIONAL USEEa
-— | Methods_used 3
— |@ void procesRequest: CH
— | Response Ketponse )
tpServuiRequest Kequest , Http Senet
— |@ void setGonkint Type C Shin
type)
—la PrinkWritens getwritr C > Sia
—T
@_void priatto (Shing s >
e String getParanetins CShing Name)
© Park geiPart CShing names
I _Shing getSubmi ted GtEName C) —_It Geb the file name
Speated by the dient 4. perurns the Fle name +
© InputStream get nputSteam C) —— Gee the Contenk ts
the part as ‘dn ‘InputStream +
@ abstract fat Had C) —— Read the neat byl of data
From the input Sheom . The Value byt is Hehirned as an
fat in the range 0-255.
@ void _writt (byte Gb) — Wribs” bitingth by les from
-the Specied byte areray te this Oulpuk Stream:
@ Void doGet (HupSewlerRequest request: » HttpSenlutResponse
! | + }
[|
Hsponse )
® void clofost C HitpSenibRequok request » Hitp ServlutResponrt
Hs ponse_)
I@ Shing _gerStrler nfo CD
“3
FOR EDUCATIONAL USE.
aCTae