Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (25 sloc) 1.34 KB

Remembrance of Things Past

Basic authentication is a lightweight solution to general authentication, but what if we need to remember a little more information about a user's session? That's where cookies come in.

Let's build on our authenticated application and add support for simple cookie handling.

@@snip { #example1 }

Now that we have a slightly more sophisitcated basic application let's mount it with a user named jim and a password of j@m.

@@snip { #example2 }

In your browser, open the url http://localhost:8080/ and you should be greeted with its native authentication dialog. Enter jim and j@m, if you are feeling authentic.

Once authenticated you should see simple text questioning your preferences. Why is this? Well, you have yet to tell the server what you prefer. In your url bar, enter the address


or whatever else you have a preference for. Now, every time you request http://localhost:8080/ the server has remembered your preference for you. This is a cookie at work!

If you change your mind you can always hit the prefer path with a new pref or just tell the server to forget it by entering the address http://localhost:8080/forget.