Cookies serve as a facility for servers to send information to a client. This information is then housed on the client, from which the server can later retrieve the information. In this article, we will study the concept of saving client state with cookies using Java Servlets. I’ll walk you through an end to end example where you will store and retrieve data using cookies.
This article is not intended to teach you about Java Servlets; I am assuming that you have a decent background knowledge of the subject. If this is not the case, you may want to take a look at the articles referenced in the resources section of the article (last page)before moving on.
You will need an application server to run the servlets you create. To do my experimentation, I used IBM WebSphere Studio Application Developer. This powerful product acts as integrated development environment (IDE) in which you can build, test, and deploy your application. Embedded within the product is also a WebSphere Test Environment, in which we can deploy our web applications for testing. Of course, you can also deploy to Apache Tomcat or some other application server, but within Application Developer, you never have to leave your development environment. You can learn more about IBM WebSphere Studio Application Developer here.