Hi everyone,
I am trying to create a simple website using cookies to remember the last 2 links visited on my site. It is a very simple 2 column website:
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing Site</title>
</head>
<body>
<table border="1" width="800" valign="top">
<tr>
<td width="300" valign="top">
<h2>Navigation</h2>
<%
if(request.getParameter("genre") == null) { %>
<p>Please select a music genre:</p>
<form action="index.jsp">
<input type="radio" name="genre" value="rock" /> Rock <br />
<input type="radio" name="genre" value="pop" /> Pop <br />
<input type="submit" value="Search" />
</form>
<% }
if (request.getParameter("genre") != null) {
if (request.getParameter("genre").equals("rock")) { %>
<p>You have chosen <%=request.getParameter("genre")%>. Here is a list of subgenres:</p>
<form action="index.jsp">
<input type="radio" name="subgenre" value="classic rock" /> Classic Rock<br />
<input type="radio" name="subgenre" value="hard rock" /> Hard Rock<br />
<input type="submit" value="Search" />
</form>
<%
}
if (request.getParameter("genre").equals("pop")) { %>
<p>You have chosen <%=request.getParameter("genre")%>. Here is a list of subgenres:</p>
<form action="index.jsp">
<input type="radio" name="subgenre" value="classic pop" /> Classic Pop <br />
<input type="radio" name="subgenre" value="jazz" /> Jazz <br />
<input type="submit" value="Search" />
</form>
<%
}
} %>
</td>
<td width="600" valign="top">
<%
if (request.getParameter("subgenre") == null) { %>
<h2>Welcome to My Website</h2>
<p>Please use the left menu to select your music genre and subgenre.</p>
<p>The last three sites you visted are: </p>
<ol>
<li>Site One</li>
<li>Site Two</li>
<li>Site Three</li>
</ol>
<%
}
if (request.getParameter("subgenre") != null) {
if (request.getParameter("subgenre").equals("classic rock")) { %>
<p>You have chosen <%=request.getParameter("subgenre")%>. Here is a list of bands:</p>
<ul>
<li>The Beatles</li>
<li>Pink Floyd</li>
<li>AC/DC</li>
<li>Aerosmith</li>
</ul>
<p>Click <a href="index.jsp">here</a> to go back to home</p>
<%
}
if (request.getParameter("subgenre").equals("hard rock")) { %>
<p>You have chosen <%=request.getParameter("subgenre")%>. Here is a list of bands:</p>
<ul>
<li>Led Zeppelin</li>
<li>Jimi Hendrix</li>
<li>Metallica</li>
<li>The Who</li>
</ul>
<p>Click <a href="index.jsp">here</a> to go back to home</p>
<%
}
if (request.getParameter("subgenre").equals("classic pop")) { %>
<p>You have chosen <%=request.getParameter("subgenre")%>. Here is a list of bands:</p>
<ul>
<li>David Bowie</li>
<li>Elton John</li>
<li>The Police</li>
<li>Buddy Holly</li>
</ul>
<p>Click <a href="index.jsp">here</a> to go back to home</p>
<%
}
if (request.getParameter("subgenre").equals("jazz")) { %>
<p>You have chosen <%=request.getParameter("subgenre")%>. Here is a list of bands:</p>
<ul>
<li>Duke Ellington</li>
<li>Kim Waters</li>
<li>Igor</li>
<li>Peter White</li>
</ul>
<p>Click <a href="index.jsp">here</a> to go back to home</p>
<%
}
}
%>
<br />
<br />
</td>
</tr>
</table>
</body>
</html>
Right now, cookies have not been implemented. I am simply organizing the flow of the website.
Now my question is: How do I add cookies to make my website remember the last 2 or 3 links visited on the website? As you can see, I just entered Site One, Site Two, and Site Three for intuitive purposes and they are static.
I am not very familiar with implementing cookies, but I do understand how they work.
Thanks in advance!