Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
180
Chapter 8 Handling Cookies
Identifying a User During an E commerce 
Session
Many on line stores use a  shopping cart  metaphor in which the user selects
an item, adds it to his shopping cart, then continues shopping. Since the
HTTP connection is usually closed after each page is sent, when the user
selects a new item to add to the cart, how does the store know that it is the
same user that put the previous item in the cart? Persistent (keep alive)
HTTP connections (see Section 7.4) do not solve this problem, since persis 
tent connections generally apply only to requests made very close together in
time, as when a browser asks for the images associated with a Web page.
Besides, many servers and browsers lack support for persistent connections.
Cookies, however, can solve this problem. In fact, this capability is so useful
that servlets have an API specifically for session tracking, and servlet authors
don't need to manipulate cookies directly to take advantage of it. Session
tracking is discussed in Chapter 9.
Avoiding Username and Password
Many large sites require you to register in order to use their services, but it is
inconvenient to remember and enter the username and password each time
you visit. Cookies are a good alternative for low security sites. When a user
registers, a cookie containing a unique user ID is sent to him. When the cli 
ent reconnects at a later date, the user ID is returned, the server looks it up,
determines it belongs to a registered user, and permits access without an
explicit username and password. The site may also remember the user's
address, credit card number, and so forth, thus simplifying later transactions.
Customizing a Site
Many  portal  sites let you customize the look of the main page. They might
let you pick which weather report you want to see, what stock and sports
results you care about, how search results should be displayed, and so forth.
Since it would be inconvenient for you to have to set up your page each time
you visit their site, they use cookies to remember what you wanted. For sim 
ple settings, this customization could be accomplished by storing the page
settings directly in the cookies. Section 8.6 gives an example of this. For more
complex customization, however, the site just sends the client a unique iden 
tifier and keeps a server side database that associates identifiers with page
settings. 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved