JSP Tutorial #23 – Cookies with JSP – Part 1



JSP Tutorial #23 – Cookies with JSP – Part 1

JSP Tutorial #23 - Cookies with JSP - Part 1

FULL COURSE: JSP, Servlets and JDBC (80+ videos)
http://www.luv2code.com/jsp (SPECIAL DISCOUNT)

—-

This JSP tutorial series will help you quickly get up to speed with JSP.

Download Tutorial Source Code: http://www.luv2code.com/downloads/youtube-jsp/jsp-tutorial-source-code-lite.zip

—-

View more videos on the playlist: JSP Tutorial: https://goo.gl/fFVMrj

Closed-Captioning and English subtitles available for this JSP Tutorial.

—-

Follow luv2code for more JSP tutorial:

Website: http://www.luv2code.com
YouTube: http://goo.gl/EV6Kwv
Twitter: http://goo.gl/ALMzLG
Facebook: http://goo.gl/8pDRdA

If you liked my JSP tutorial, then join my mailing list: Get exclusive access to new Java tutorials.

– http://www.luv2code.com/joinlist

Questions or problems about this JSP tutorial? Post them in the comments section below.

Want to suggest a video for my JSP tutorial? Leave a comment below. I’m always looking for new video ideas.

Let me know what video you’d like for me to create.

Premium JSP Course

Need More Details on JSP?
– See my Premium JSP and Servlets course (80+ videos)
– http://www.luv2code.com/jsp

Hello! In this video we’re gonna learn how to use cookies with JSP.

So I’ll cover the following topics … First off, we’ll find out what are cookies and how we can use them. And then we’ll actually explore the cookies API and learn how to write code for reading and writing cookies. All right, so we have a lot of good things in store in this video … let’s go ahead and get started.

So, what’s the purpose of cookies and, uh, you may have heard of cookies before but basically cookies allow you to personalize a website for user. And so in effect you can actually keep track of any user preferences, uh, say for example you have a new site and a user chose their favorite programming language as Java. Then you can keep track of that and show them Java news in the future. Or if you have a travel site and they frequently fly from a given airport, then you can show them all flights from that given airport. So it allows you to keep track of long term preferences for user, even after they close their browser, and restart it.

All right so let’s look at an example here, uh, so I’ll use that Expedia.com travel site, uh, again I use this website a lot because I travel frequently between Philadelphia and India. So here in this form, I’ll just go ahead and setup my departure city of where I’m flying from, Philadelphia PA in the US, and I travel to Bangalore a good deal, in India. So I’ll just setup the departure date, just making this up right now, my departure date and my return date. But the key here is that once I do a search, Expedia will go off and find flights for me from Philadelphia to Bangalore.

Now, the nice thing about it is that Expedia will actually create a cookie, and store it on my browser such that when they come back at a later time or actually, when I come back at a later time, Expedia will remember it’s like, hey, your last flight that you searched for was Philadelphia to Bangalore, and here’s some new prices. So I’ll go ahead and quit my browser right now. And then I’ll start the browser again from scratch. And so now I have my browser back up and then I actually go into Expedia again, and they’ll actually remember information about my previous operation. And again they are making use of cookies, they are keeping track of my preferences so they automatically know that I’m gonna go from Philadelphia, uh, to Bangalore. Just as a suggestion, and they make use of cookies, for this type of functionality. Which is really cool. And I’ll actually show you how to write Java code, or JSP code, for reading cookies, and also, writing cookies.

All right, so again, what is a cookie? Well it’s basically text data that’s exchanged between the web browser and server. So this is functionality that’s built into the browser. So if your web browser, when you visit a given server, that browser will send over cookies to that server. And so that’s how that Expedia.com website was able to remember my information. Says, oh great, you’ve been to Expedia before. They read my cookies, they found out my departure and destination city, and displayed a custom form for me. Umm, the site can also create new cookies, and send them to my browser to keep track of information, for any of my return visits. So that’s the idea of a cookie and so I’ll actually show you the server side code for reading cookies, and also, writing cookies and sending them back to the browser.

Now, what exactly is in a cookie? Well, you can kind of think of a cookie as just like a, name value pair. So I, a cookie has a given name, like in this example, my app dot favorite language, and then the value could be ruby. So that’s one cookie. And the application can actually make use of multiple cookies.

[Snip] for complete transcript of JSP tutorial, select “More … Transcript”

Comments are closed.