--- /dev/null
+<html>
+<body>
+
+<form action="setcookie.jsp">
+ First name:<br>
+ <input type="text" name="firstname"><br>
+ Last name:<br>
+ <input type="text" name="lastname"><br><br>
+ <input type="submit" value="Submit">
+</form>
+
+</body>
+</html>
<html>
<body>
- Bonjour <% out.print(session.getAttribute("firstname")); %> <% out.print(session.getAttribute("lastname")); %>, <% out.print(session.getAttribute("age")); %> years old
- living at <% out.print(session.getAttribute("address")); %> working as <% out.print(session.getAttribute("work")); %>
+ Bonjour <% out.print(session.getAttribute("firstname")); %>
+ <% out.print(session.getAttribute("lastname")); %>,
+ <% out.print(session.getAttribute("age")); %> years old
+ living at <% out.print(session.getAttribute("address")); %>
+ working as <% out.print(session.getAttribute("work")); %>
</body>
</html>
--- /dev/null
+<%@ page import="java.io.*, java.util.*, javax.servlet.*" %>
+<%
+String firstname = request.getParameter("firstname");
+String lastname = request.getParameter("lastname");
+String username = firstname + lastname;
+Date timestamp = new Date();
+Cookie cookie = new Cookie("username", username);
+cookie.setMaxAge(60*60*24); //24 hours
+response.addCookie(cookie);
+%>
+
+<html>
+ <body>
+ <a href="viewcookie.jsp">Continue</a>
+ </body>
+</html>
--- /dev/null
+<% Cookie[] cookies = request.getCookies(); %>
+
+<html>
+ <body>
+ Bonjour <br>
+ <%
+ for(int i = 0; i < cookies.length; i++) {
+ Cookie c = cookies[i];
+ out.println(c.getName() + " = " + c.getValue() + " <br>");
+ }
+ %>
+ </body>
+</html>