O'Reilly logo

Java Extreme Programming Cookbook by Brian M. Coyner, Eric M. Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Cookies

Problem

You want to test a servlet that uses cookies.

Solution

Write a ServletTestCase that tests if your servlet correctly handles creating and managing cookies.

Discussion

Cookies are small pieces of information passed back and forth between the web server and the browser as a user navigates a web application. Web applications commonly use cookies for session tracking because a cookie’s value uniquely identifies the client. There is a danger for a web application to rely solely on cookies for session tracking because the user may, at any time, disable cookies. For this reason, you must design your web application so that your web application still works if cookies are disabled.

Example 7-5 shows how to write a test for a servlet that uses cookies to keep track of how ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required