IT2255 Web Essentials - Unit V Servlets and Database Connectivity
1,043 views
31 slides
May 17, 2023
Slide 1 of 31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
About This Presentation
Servlets: Java Servlet Architecture – Servlet Life cycle – Form GET and POST actions – Sessions – Cookies – Database connectivity – JDBC
Size: 619.36 KB
Language: en
Added: May 17, 2023
Slides: 31 pages
Slide Content
IT2253 Web Essentials
Unit V –Servlets and Database Connectivity
Kaviya.P
Kamaraj College of Engineering & Technology
Unit IV –Servlets and Database Connectivity
Servlets:JavaServletArchitecture–ServletLifecycle
–FormGETandPOSTactions–Sessions–Cookies–
Databaseconnectivity–JDBC–Creationofsimple
interactiveapplications–Simpledatabaseapplications
Servlet Life Cycle
ServletLifeCycleMethods
•init():TheServlet.init()methodiscalledbytheServletcontainerto
indicatethatthisServletinstanceisinstantiatedsuccessfullyandisaboutto
putintoservice.
•service():ItisinvokedtoinformtheServletabouttheclientrequests.
•destroy():ItrunsonlyonceduringthelifetimeofaServletandsignalsthe
endoftheServletinstance.
Servlet Life Cycle
ServletLifeCycleMethods
Form GET and POST Actions
GETMethod
•TheGETmethodsendstheencodeduserinformationappendedtothepagerequest.
•Thepageandtheencodedinformationareseparatedbythe?(questionmark)
symbol.
•TheGETmethodisthedefaultmethodtopassinformationfrombrowsertoweb
server.
•TheGETmethodhassizelimitation:only1024characterscanbeusedinarequest
string.
•ServlethandlesthistypeofrequestsusingdoGet()method.
•Example
http://www.test.com/hello?key1 = value1&key2 = value2
Form GET and POST Actions
POSTMethod
•MorereliablemethodofpassinginformationtoabackendprogramisthePOST
method.
•ThispackagestheinformationinexactlythesamewayasGETmethod,butinstead
ofsendingitasatextstringaftera?(questionmark)intheURLitsendsitasa
separatemessage.
•ServlethandlesthistypeofrequestsusingdoPost()method.
Form GET and POST Actions
ReadingFormDataUsingServlet
•getParameter()−Callrequest.getParameter()methodtogetthevalueofaform
parameter.
•getParameterValues()−Callthismethodiftheparameterappearsmorethanonce
andreturnsmultiplevalues,forexamplecheckbox.
•getParameterNames()−Callthismethodifyouwantacompletelistofall
parametersinthecurrentrequest.