The aim of this workshop is to create a cookie cutter JSP that creates cookies.
This workshop should take no longer than 60 minutes.
The following demonstrates the objective of this workshop.
This file already contains some code that displays a table of all cookies that are currently registered by the web server on the client machine. Read this code and make sure you understand what is going on. Below this table is a form that allows the user to provide a name and value for a cookie. This form sends this data to 'makecookie.jsp' which is the JSP we are going to write.
<HTML> <HEAD> <TITLE>JSP Course - Request Workshop</TITLE> </HEAD> <BODY> <P><%= strMsg %></P> <P>Click back in your browser to view previous form, select refresh and see if your new cookie has indeed been created.</P> </BODY> </HTML>
<HTML> statement add a new script block. Here we will add the
code to create a cookie. As part of this process we want to update strMsg with
a message to say that either the cookie was successfully created or if there was a problem.
String strMsg;
String strCookieName =
request.getParameter("CookieName");
String strCookieValue =
request.getParameter("CookieValue");
strCookieName
if((strCookieName!=null)
&&(!strCookieName.equals("")))
{
}
else
{
strMsg = "Must provide a cookie name.";
}
if..else statement to check strCookieValue.
Cookie c =
new Cookie(strCookieName,strCookieValue);
response.addCookie(c);
strMsg = "Cookie successfully created.";
If you couldn't get your solution to work then click the icon to display the source code.

The next section looks at the session and application objects