Professional Documents
Culture Documents
Home
Core Java
Servlet
JSP
Struts2
Mail API
Hibernate
Spring
Android
Projects
Interview Q
Comment
<<prev
Forum
next>>
Basics of Servlet Servlet Basics of Servlet Servlet API Servlet Interface GenericServlet HttpServlet Servlet Life Cycle Steps to create a servlet in Tomcat How servlet works? Servlet with IDE servlet in Myeclipse servlet in Eclipse servlet in Netbeans ServletRequest Servlet Collaboration RequestDispacher sendRedirect ServletConfig ServletContext Attribute Session Tracking Cookies Hidden Form Field URL Rewriting HttpSession Event and Listener Filter
Session Tracking
Session simply means a particular interval of time. Session Tracking is a way to maintain state of an user. Http protocol is a stateless protocol. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.
Cookies in Session Tracking Session Tracking Session Tracking Techniques Cookies javax.servlet.http.Cookie class Example of using Cookies
1/7/13
Filter Authentication Filter FilterConfig Useful examples ServletInputStream ServletOutputStream Annotation Servlet SingleThreadModel SSI Development Registration Example Fetching records for the given rollno Improving Performance Uploading file Downloading file Sending Email by Servlet Write data to PDF Login Example Writing Image
1) Cookies
A cookie is a small piece of information that is persisted between the multiple client requests.A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
w w w .javatpoint.com/cookies-in-session-tracking
2/8
1/7/13
javax.servlet.http.Cookie class
javax.servlet.http.Cookie class provides the functionality of using cookies.
Advantage of Cookies
1. Simplest technique of maintaining the state. 2. Cookies are maintained at client side.
Disadvantage of Cookies
w w w .javatpoint.com/cookies-in-session-tracking 3/8
1/7/13
1. It will not work if cookie is disabled from the browser. 2. Only textual information can be set in Cookie object.
index.html
<omato=srlt"mto=ps" fr cin"eve1 ehd"ot> Nm:ipttp=tx"nm=ueNm">b/ ae<nu ye"et ae"srae/<r> <nu tp=sbi"vle"o/ ipt ye"umt au=g"> <fr> /om
w w w .javatpoint.com/cookies-in-session-tracking 4/8
1/7/13
FirstServlet.java
ipr jv.o* mot aai.; ipr jvxsrlt* mot aa.eve.; ipr jvxsrltht.; mot aa.eve.tp*
pbi casFrteve etnsHtSrlt{ ulc ls isSrlt xed tpeve pbi vi dPs(tpeveRqetrqet HtSrltepnersos) ulc od ootHtSrlteus eus, tpeveRsos epne{ ty r{ rsos.eCnetye"ethm"; epnestotnTp(tx/tl) Pitrtrot=rsos.eWie(; rnWie u epnegtrtr) Srn nrqetgtaaee(ueNm"; tig =eus.ePrmtr"srae) otpit"ecm "n; u.rn(Wloe +) Coi c=e Coi(uae,)/cetn coi ojc oke knw oke"nm"n;/raig oke bet rsos.dCoi(k;/digcoi i tersos epneadokec)/adn oke n h epne /cetn sbi bto /raig umt utn otpit"fr ato=srlt'"; u.rn(<om cin'eve2>) otpit"ipttp=sbi'vle'o>) u.rn(<nu ye'umt au=g'"; otpit"/om"; u.rn(<fr>) otcoe) u.ls(; }ac(xeto e{ytmotpitne; cthEcpin )Sse.u.rnl()} } }
SecondServlet.java
1/7/13
ipr jvxsrltht.; mot aa.eve.tp* pbi casScnSrltetnsHtSrlt{ ulc ls eodeve xed tpeve
pbi vi dPs(tpeveRqetrqet HtSrltepnersos) ulc od ootHtSrlteus eus, tpeveRsos epne{ ty r{ rsos.eCnetye"ethm"; epnestotnTp(tx/tl) Pitrtrot=rsos.eWie(; rnWie u epnegtrtr) Coi c[=eus.eCois) oke k]rqetgtoke(; otpit"el "c[]gtau() u.rn(Hlo +k0.eVle); otcoe) u.ls(; }ac(xeto e{ytmotpitne; cthEcpin )Sse.u.rnl()} }
web.xml
<e-p> wbap <eve> srlt <eve-aes<srltnm> srltnm>1/eve-ae <eve-ls>isSrlt/eve-ls> srltcasFrteve<srltcas <srlt /eve> <eve-apn> srltmpig <eve-aes<srltnm> srltnm>1/eve-ae <r-atr>srlt<ulpten ulpten/eve1/r-atr> <srltmpig /eve-apn> <eve> srlt <eve-aes<srltnm> srltnm>2/eve-ae <eve-ls>eodeve<srltcas srltcasScnSrlt/eve-ls> <srlt /eve>
w w w .javatpoint.com/cookies-in-session-tracking 6/8
1/7/13
<srlt /eve>
<eve-apn> srltmpig <eve-aes<srltnm> srltnm>2/eve-ae <r-atr>srlt<ulpten ulpten/eve2/r-atr> <srltmpig /eve-apn> <wbap /e-p>
download this example (developed using Myeclipse IDE) download this example (developed using Eclipse IDE) download this example (developed using Netbeans IDE)
<<prev next>>
136
0
Google +
Tw eet
27
Like
2.3k
javatpoint.com on Facebook
Like 2,377 people like javatpoint.com.
w w w .javatpoint.com/cookies-in-session-tracking
Deepak
S uren
S iv a
Rav i
Ibkar
V amsee
G aurav
P ramod
S ureshreddy
Krishna
H emant
Bhanu
7/8
1/7/13
H arini
V ijay
N atasha
S achin
N itish
Jas Ram
C hera
S elv a
S hashi
Rav i
V ipul
A run
P riy a
Kaushal
H itesh
S rinu
A mit
Like the www.javatpoint.com on facebook / google+ / twitter / subscribe to get latest updates
Sitemap javatpoint.com is developed Core Java Servlet JSP Struts2 Hibernate Spring Interview Questions
to provide easy and point to point learning and training in detail. Examples might be simplified to improve reading and basic understanding. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. If there is any mistake, please mail to sonoojaiswal1987@gmail.com. We provide assurance of 90% interview questions. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 2011-2012. All Rights Reserved.
w w w .javatpoint.com/cookies-in-session-tracking
8/8