How do I send cookies from a client to a servlet?
Author: Deron Eriksson
Description: This Java tutorial describes how to send cookies from a client to a servlet.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1 || Tomcat 5.5.20

Page: < 1 2

(Continued from page 1)

If we fire up the servletW, and then we execute the client class, we see the following results.

CookieTestClient output

As you can see, the servlet receives the request from the client which includes the testCookie1 and testCookie2 cookiesW sent from the client. The servlet writes the message "This is the CookieW Test Servlet" to the response followed by the two cookieW names and their values. The CookieTestClient receives this response, and outputs it to the console.

Page: < 1 2