Module 4.pptModule 4.pptModule 4.pptModule 4.ppt

tahirnaquash2 42 views 84 slides Jul 10, 2024
Slide 1
Slide 1 of 84
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84

About This Presentation

Module 4.pptModule 4.pptModule 4.ppt


Slide Content

Java
Servlets
Module 4

Contents
1.The life cycle of a servlet;
2.A simple servlet;
3.the servlet API;
4.The javax.servletpackage
5.Reading servlet parameter;
6.the javax.servlet.httppackage;
7.Handling HTTP Requests and
Responses;
8.using Cookies;

Contents
9.Session Tracking,
10.Java Server Pages (JSP); JSP tags,
Variables and Objects, Methods,
11.Control statements, Loops,
12.Request String,
13.Parsing other information,
14.User sessions,
15.Cookies, Session Objects

Java Servlets
Technology Overview

Background
Howwebbrowsersandserverscooperatetoprovidecontenttoa
user?
•Considerarequestforastaticwebpage.AuserentersaURLinto
abrowser.ThebrowsergeneratesanHTTPrequesttothe
appropriatewebserver.
•Thewebservermapsthisrequesttoaspecificfile.Thatfileis
returnedinanHTTPresponsetothebrowser.TheHTTPheaderin
theresponseindicatesthetypeofthecontent.
•TheMultipurposeInternetMailExtensions(MIME)areusedfor
thispurpose.
•Forexample,ordinaryASCIItexthasaMIMEtypeoftext/plain.
TheHypertextMarkupLanguage(HTML)sourcecodeofaweb
pagehasaMIMEtypeoftext/html.

Background

What is a Java Servlets?
•AJavaservletisaserver-sideprogramthatiscalled
bytheuserinterfaceoranotherJ2EEcomponentand
containsthebusinesslogictoprocessarequest.
•AJavaServerPageisalsoaserver-sideprogramthat
performspracticallythesamedutiesasaJavaservlet
usingadifferenttechnique.
•BothaJavaservletandaJavaServerPagecallother
componentsthathandleprocessingdetails.

Servlet Services
•JavaServletsprovidemanyusefulservices
Provideslow-levelAPIforbuildingInternetservices
ServesasfoundationtoJavaServerPages(JSP)and
JavaServerFaces(JSF)technologies
Candelivermultipletypesofdatatoanyclient
XML,HTML,WML,GIF,etc...
Canserveas“Controller”ofJSP/Servletapplication

Why Use Servlets?
•Portability
Write once, serve everywhere
•Power
Can take advantage of all Java APIs
•Elegance
Simplicity due to abstraction
•Efficiency & Endurance
Highly scalable

Why Use Servlets?
•Safety
Strongtype-checking
Memorymanagement
•Integration
Servletstightlycoupledwithserver
•Extensibility&Flexibility
Servletsdesignedtobeeasilyextensible,though
currentlyoptimizedforHTTPuses
Flexibleinvocationofservlet(SSI,servlet-chaining,
filters,etc.)

A Simple Servlet
•Tobecomefamiliarwiththekeyservletconcepts,we
willbeginbybuildingandtestingasimpleservlet.
•Thebasicstepsarethefollowing:
1.Createandcompiletheservletsourcecode.Then,
copytheservlet’sclassfiletotheproperdirectory,
andaddtheservlet’snameandmappingstothe
properweb.xmlfile.
2.StartTomcat.
3.Startawebbrowserandrequesttheservlet.

Time Servlet –Example
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
publicclassTimeServletextendsHttpServlet{
public void doGet(HttpServletRequest aRequest,
HttpServletResponse aResponse)
throwsServletException,IOException{
PrintWriterout=aResponse.getWriter();
out.println("<HTML>");
out.println("Thetimeis:"+
newjava.util.Date());
out.println("</HTML>");
}
}

Java Servlets
Technical Architecture

Servlets Architecture
•TheHttpServletclass
Servesclient'sHTTPrequests
•ForeachoftheHTTPmethods,GET,POST,and
others,thereiscorrespondingmethod:
doGet(…)–servesHTTPGETrequests
doPost(…)–servesHTTPPOSTrequests
doPut(…),doHead(…),doDelete(…),doTrace(…),
doOptions(…)
•TheServletusuallymustimplementoneofthe
firsttwomethodsortheservice(…)method

Servlets Architecture
•The HttpServletRequestobject
Contains the request data from the client
HTTP request headers
Form data and query parameters
Other client data (cookies, path, etc.)
•The HttpServletResponseobject
Encapsulates data sent back to client
HTTP response headers (content type, cookies,
etc.)
Response body (as OutputStream)

Servlets Architecture
•The HTTP GET method is used when:
The processing of the request does not change the state of
the server
The amount of form data is small
You want to allow the request to be bookmarked
•The HTTP POST method is used when:
The processing of the request changes the state of the
server, e.g. storing data in a DB
The amount of form data is large
The contents of the data should not be visible in the URL
(for example, passwords)

Java Servlets
Life Cycle

Servlets Life-Cycle
•Youcanprovideanimplementationofthesemethods
inHttpServletdescendentclassestomanipulatethe
servletinstanceandtheresourcesitdependson
•The Web container
manages the life cycle
of servlet instances
•The life-cycle methods
should not be called by
your code
init()
...()
service()
doGet()
doPost()
doDelete()
destroy()
doPut()
New Destroyed
Running

Servlets Life-Cycle

The init() Method
•CalledbytheWebcontainerwhentheservlet
instanceisfirstcreated
•TheServletsspecificationguaranteesthatno
requestswillbeprocessedbythisservletuntilthe
init()methodhascompleted
•Overridetheinit()methodwhen:
Youneedtocreateoropenanyservlet-specific
resourcesthatyouneedforprocessinguser
requests
Youneedtoinitializethestateoftheservlet
publicvoidinit(ServletConfig config)
throwsServletException

The service() Method
•CalledbytheWebcontainertoprocessauser
request
•DispatchestheHTTPrequeststodoGet(…),
doPost(…),etc.dependingontheHTTPrequest
method(GET,POST,andsoon)
SendstheresultasHTTPresponse
•Usuallywedonotneedtooverridethismethod
publicvoidservice(ServletRequest request,
ServletResponse response)throwsServletException,IOException

The destroy() Method
•Called by the Web container when the servlet
instance is being eliminated
•The Servlet specification guarantees that all
requests will be completely processed before this
method is called
•Override the destroy method when:
You need to release any servlet-specific
resources that you had opened in the init()
method
You need to persist the state of the servlet
publicvoiddestroy()

Servlets API
The javax.servlet Package

Servlets API
•Two packages contain the classes and interfaces that
are required to build the servlets .
•These are javax.servletand javax.servlet.http. They
constitute the core of the Servlet API.
•Keep in mind that these packages are not part of the
Java core packages.
•Therefore, they are not included with Java SE. Instead,
they are provided by Tomcat.
•They are also provided by Java EE.

The javax.servletPackage
•Thiscontainsanumberofinterfacesandclassesthatestablish
theframeworkinwhichservletsoperate

The Servlet Interface
•All servlets must implement the Servlet interface.
•It declares the init( ), service( ), and destroy( ) methods that
are called by the server during the life cycle of a servlet.
•A method is also provided that allows a servlet to obtain any
initialization parameters.
•These methods are invoked by the server.
•The getServletConfig( ) method is called by the servlet to
obtain initialization parameters.
•A servlet developer overrides the getServletInfo( ) method
to provide a string with useful information (for example, the
version number). This method is also invoked by the server.

The Methods Defined by Servlet

The ServletConfigInterface
•TheServletConfiginterfaceallowsaservlettoobtain
configurationdatawhenitisloaded.
•Themethodsdeclaredbythisinterfacearesummarizedhere:

The ServletContextInterface
•TheServletContextinterfaceenablesservletstoobtain
informationabouttheirenvironment.

The ServletRequestInterface
•TheServletRequestinterfaceenablesaservlettoobtain
informationaboutaclientrequest.

The ServletRequestInterface

The ServletResponseInterface
•TheServletResponseinterfaceenablesaservlettoformulatea
responseforaclient.

Reading Servlet
Parameters
Examples

Processing Parameters –Hello
Servlet
•We want to create a servlet that takes an user name
as a parameter and says "Hello, <user_name>"
•We need HTML form with a text field
•The servlet can later retrieve the value entered in the
form field
<form method="GET or POST" action="the servlet">
<input type="text" name="user_name">
</form>
String name =request.getParameter("user_name");

Hello Servlet –Example
<html><body>
<form method="GET" action="HelloServlet">
Please enter your name:
<input type="text" name="user_name">
<input type="submit" value="OK">
</form>
</body></html>
HelloForm.html

HelloServlet.java
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
String userName = request.getParameter("user_name");
out.println("<html><head>");
out.println("\t<title>Hello Servlet</title>");
out.println("</head><body>");
out.println("\t<h1>Hello, " + userName + "</h1>");
out.println("</body></html>");
}
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet {

Parameter Servlet –Example 1
<html>
<body> <center><form name="Form1" method="post"
action="http://localhost:8080/servlets -examples/
servlet/PostParametersServlet">
<table>
<tr> <td><B>Employee</td>
<td><input type=textbox name="e" size="25"
value=""></td>
</tr>
<tr> <td><B>Phone</td>
<td><input type=textbox name="p" size="25"
value=""></td>
</tr></table>
<input type=submit value="Submit">
</body>
</html>
PostParameters.html,

Parameter Servlet –Example 1
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class PostParametersServlet extends
GenericServlet {
public void service(ServletRequest request,
ServletResponse response)throws ServletException,
IOException {
PrintWriter pw = response.getWriter();
Enumeration e = request.getParameterNames();
while(e.hasMoreElements()) {
String pname = (String)e.nextElement();
pw.print(pname + " = ");
String pvalue = request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
}
}
PostParametersServlet.java

Servlets API
The javax.servlet.http Package

The javax.servlet.httpPackage
•Theclassesandinterfacesdefinedinjavax.servlet,suchas
ServletRequest,ServletResponse,andGenericServlet,will
illustratethebasicfunctionalityofservlets.
•However,whenworkingwithHTTP,youwillnormallyusethe
interfacesandclassesinjavax.servlet.http.

Servlets API
•The most important servlet functionality:
RetrievetheHTMLformparametersfromthe
request(bothGETandPOSTparameters)
Retrieve a servlet initialization parameter
Retrieve HTTP request header information
HttpServletRequest.getParameter(String)
ServletConfig.getInitParameter()
HttpServletRequest.getHeader(String)

Servlets API
Set an HTTP response header/content type
Acquire a text stream for the response
Acquire a binary stream for the response
Redirect an HTTP request to another URL
HttpServletResponse.setHeader(<name>, <value>) /
HttpServletResponse.setContentType(String)
HttpServletResponse.getWriter()
HttpServletResponse.getOutputStream()
HttpServletResponse.sendRedirect()

The Cookie Class
•TheCookieclassencapsulatesacookie.Acookieisstored
onaclientandcontainsstateinformation.Cookiesare
valuablefortrackinguseractivities.
•Aservletcanwriteacookietoauser’smachineviathe
addCookie()methodoftheHttpServletResponseinterface.
Thedataforthatcookieisthenincludedintheheaderofthe
HTTPresponsethatissenttothebrowser.
•Thenamesandvaluesofcookiesarestoredontheuser’s
machine.
1.Thenameofthecookie
2.Thevalueofthecookie
3.Theexpirationdateofthecookie
4.Thedomainandpathofthecookie

Handling HTTP
Requests and
Responses
The javax.servlet.http Package

Handling HTTP Requests and
Responses
•TheHttpServletclassprovidesspecializedmethodsthat
handlethevarioustypesofHTTPrequests.
•Aservletdevelopertypicallyoverridesoneofthese
methods.ThesemethodsaredoDelete(),doGet(),
doHead(),doOptions(),doPost(),doPut(),anddoTrace(
).
•However,theGETandPOSTrequestsarecommonlyused
whenhandlingforminput.Therefore,thissection
presentsexamplesofthesecases.

Handling HTTP GET Requests
ColorGet.html
<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/examples/servlets/servle
t/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>

Handling HTTP GET Requests
ColorGetServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorGetServlet extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
String color= request.getParameter ("color");
response.setContentType ("text/html");
PrintWriterpw = response.getWriter();
pw.println("<B>The selected coloris: ");
pw.println(color);
pw.close();
}
}

Handling HTTP POST Requests
ColorGet.html
<html>
<body>
<center>
<form name="Form1"
method="post"
action="http://localhost:8080/examples/servlets/servle
t/ColorPostServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>

Handling HTTP POST Requests
ColorGetServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorPostServlet extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
String color= request.getParameter ("color");
response.setContentType ("text/html");
PrintWriterpw = response.getWriter();
pw.println("<B>The selected coloris: ");
pw.println(color);
pw.close();
}
}

Using Cookies

Using Cookies
AddCookie.html
<html>
<body>
<center>
<form name="Form1"
method="post"
action="http://localhost:8080/examples/servlets/servle
t/AddCookieServlet">
<B>Enter a value for MyCookie:</B>
<input type=textbox name="data" size=25 value="">
<input type=submit value="Submit">
</form>
</body>
</html>

Using Cookies
AddCookieServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
String data = request.getParameter ("data");
Cookie cookie= new Cookie("MyCookie", data);
response.addCookie(cookie);
response.setContentType ("text/html");
PrintWriterpw = response.getWriter();
pw.println("<B>MyCookiehas been set to");
pw.println(data);
pw.close();
}
}

Session Tracking

Session Tracking
•HTTPisastatelessprotocol.Eachrequestisindependentofthe
previousone.
•However,insomeapplications,itisnecessarytosavestate
informationsothatinformationcanbecollectedfromseveral
interactionsbetweenabrowserandaserver.Sessionsprovidesuch
amechanism.
•AsessioncanbecreatedviathegetSession()methodof
HttpServletRequest.
•AnHttpSessionobjectisreturned.Thisobjectcanstoreasetof
bindingsthatassociatenameswithobjects.
•ThesetAttribute(),getAttribute(),getAttributeNames(),and
removeAttribute()methodsofHttpSessionmanagethesebindings.
•Sessionstateissharedbyallservletsthatareassociatedwitha
client.

Session Tracking
public class DateServletextends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
// Get the HttpSessionobject.
HttpSessionhs= request.getSession(true);
response.setContentType ("text/html");
PrintWriterpw = response.getWriter();
pw.print("<B>");
Date date= (Date)hs.getAttribute("date");
if(date != null) {
pw.print("Last access: " + date + "< br>");
}
date = new Date();
hs.setAttribute("date", date);
pw.println("Current date: " + date);
}
}

Session Tracking
•WhenyoucallgetSession()eachuserisautomatically
assignedauniqueSessionID
•HowdoesthisSessionIDgettotheuser?
•Option1:Ifthebrowsersupportscookies,the
servletwillautomaticallycreateasessioncookie,
andstorethesessionIDwithinthecookieIn
Tomcat,thecookieiscalledJSESSIONID
•Option2:Ifthebrowserdoesnotsupportcookies,
theservletwilltrytoextractthesessionIDfrom
theURL

Problems
1.Createaservletthatprintsinatablethenumbers
from1to1000andtheirsquareroot.
2.Createaservletthattakesasparameterstwointeger
numbersandcalculatestheirsum.
CreateaHTMLformthatinvokestheservlet.Tryto
useGETandPOSTmethods.
3.Implementaservletthatplaysthe"Numberguess
game".Whentheclientfirstinvoketheservletit
generatesarandomnumberintherange[1..100].The
userisaskedtoguessthisnumber.Ateachguessthe
servletsaysonly"greater"or"smaller".Thegame
endswhentheusertellthenumber.

Java Server
Pages
(JSP)

Java Server Page (JSP)
•JSP(JavaServerPages)isserversidetechnologyto
createdynamicjavawebapplication.
•AllowsJavaprogrammingcodetobeembeddedinthe
HTMLpages.
•JSPcontainsanextensionof.jsp
•AfterexecutionofaJSPpageaplainHTMLis
producedanddisplayedintheclient'sWebbrowser.
•JSPcanbethoughtasanextensiontoservlet
technologybecauseitprovidesfeaturestoeasily
createuserviews.

Java Server Page Architecture

Java Server Page Life Cycle
Web
Server
hello.jsp hello_jsp.java
Step: 1
Step: 2
hello_jsp.class
Step: 3
Step: 4Step: 5
jspInit()Create
Step: 6
jspService()
Step: 7
jspDestroy()
Web
Container
JSP Life Cycle

Web Container
•WebContainertranslatesJSPcodeintoaservletclass
source(.java)file,thencompilesthatintoajavaservlet
class.
•Inthenextstep,theservletclassbytecodeisloadedusing
classloader.TheContainerthencreatesaninstanceof
thatservletclass.
•Theinitializedservletcannowservicerequest.Foreach
requesttheWebContainercallthejspService()method.
•WhentheContainerremovestheservletinstancefrom
service,itcallsthejspDestroy()methodtoperformany
requiredcleanup.

JSP Life Cycle Phases
1.Translation–JSPpagesdoesn’tlooklikenormaljava
classes,actuallyJSPcontainerparsetheJSPpages
andtranslatethemtogeneratecorrespondingservlet
sourcecode.IfJSPfilenameishello.jsp,usuallyits
namedashello_jsp.java.
2.Compilation–Ifthetranslationissuccessful,then
containercompilesthegeneratedservletsourcefileto
generateclassfile.
3.ClassLoading–OnceJSPiscompiledasservletclass,
itslifecycleissimilartoservletanditgetsloadedinto
memory.

JSP Life Cycle Phases
4.InstanceCreation–AfterJSPclassisloadedinto
memory,itsobjectisinstantiatedbythecontainer.
5.Initialization–TheJSPclassistheninitializedandit
transformsfromanormalclasstoservlet.
6.RequestProcessing–Foreveryclientrequest,anew
threadisspawnedwithServletRequestand
ServletResponsetoprocessandgeneratetheHTML
response.
7.Destroy–LastphaseofJSPlifecyclewhereit’s
unloadedintomemory.

JSP Lifecycle Methods
•OnceaJSPpageistranslatedtoaservlet,thecontainer
invokesthefollowinglifecyclemethodsontheservlet:
1.jspInit():Thismethodisinvokedatthetimewhenthe
servletisinitialized.
2.jspService():Thismethodisinvokedwhenrequest
fortheJSPpageisreceived.
3.jspDestroy():Thismethodisinvokedbeforethe
servletisremovesfromtheservice.

What happens to a JSP page when it is
translated into Servlet

JSP Tags (Elements)
•EXPRESSIONenclosedin<%=and%>markers
AexpressionisusedtoinserttheresultofaJava
expressiondirectlyintotheoutput.
•SCRIPTLETenclosedin<%and%>markers:
AscriptletcancontainanynumberofJAVAlanguage
statements,variableormethoddeclarations,or
expressionsthatarevalidinthepagescripting
language.
<%
String message = “Hello World”;
out.println (message);
%>
The time is : <%= new java.util.Date() %>

JSP Tags (Elements)
•DIRECTIVES syntax -<%@ directive attribute = "value" %>
A JSP directive gives special information about the JSP page to the
JSP Engine.
There are three main types of directive :-
page : processing information for this page
include : files to be included
taglib : tag library to be used in the page

JSP Tags (Elements)
•DECLARATIONenclosedin<%!and%>markers
Thistagallowsthedevelopertodeclarevariablesor
methods.
•Codeplacedinthismustendinasemicolon(;).
•Declarationsdonotgenerateoutput,soareusedwith
JSPexpressionsorscriptlets.

Variables and Objects

Variables and Objects

Methods

Methods

Control Statements

Loops

Loops

Request String
•Abrowsergeneraterequeststringwheneverthesubmit
buttonisselected.Theuserrequeststhestringconsistsof
URLandthequerythestring.
Exampleofrequeststring:
http://www.jimkeogh.com/jsp/?fname=”Bob”&lname
=”Smith”
•Yourjspprogramneedstoparsethequerystringtoextract
thevaluesoffieldsthataretobeprocessedbyyour
program.Youcanparsethequerystringbyusingthe
methodsoftherequestobject.
•getParameter(Name)methodusedtoparseavalueofa
specificfieldthataretobeprocessedbyyourprogram

Request String
•codetoprocesstherequeststring
<%!StringFirstName=requst.getParameter(fname);
StringLastName=requst.getParameter(lname);%>
•Copyingfrommultivaluedfieldsuchasselectionlistfieldcan
betrickymultivaluedfieldsarehandledbyusing
getParameterValues()
•Otherthanrequeststringurlhasprotocols,portno,thehost
name
•Example
<%! String [ ] EMAIL= request. getParameterValues("EMAILADDRESS ") %>
<P><%= EMAIL [0])%> < / P>
<P><%= EMAIL [1]%> </P>

User Session
•AJSPprogrammustbeabletotrackasessionasaclient
movesbetweenHTMLpagesandJSPprograms.Thereare
threecommonlyusedmethodstotrackasession.
•Theseare
1.byusingahiddenfield,
2.byusingacookie,or
3.byusingaJavaBean,

Hidden Field
•AhiddenfieldisafieldinanHTMLformwhosevalueisn't
displayedontheHTMLpage
•YoucanassignavaluetoahiddenfieldinaJSPprogram
beforetheprogramsendsthedynamicHTMLpagetothe
browser.
•AwebservercansendahiddenHTMLformfieldalongwith
auniquesessionIDasfollows
<input type = "hidden" name = "sessionid" value = "12345">
•Eachtimethewebbrowsersendstherequestback,the
session_idvaluecanbeusedtokeepthetrackofdifferent
webbrowsers.

Cookies-create a cookie.

Cookies-Read a cookie.

Session Objects.
How to create a session attribute.

Session Objects.
How to read session attributes.