From: Jérôme Benoit Date: Wed, 11 Apr 2018 07:57:04 +0000 (+0200) Subject: exo7: add cookies handling code. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=27e8c3cf51769dd944bc3d49a5c5776bfcb8aa65;p=TD_webapps.git exo7: add cookies handling code. Signed-off-by: Jérôme Benoit --- diff --git a/ROOT/exo7/cookie-form.html b/ROOT/exo7/cookie-form.html new file mode 100644 index 0000000..10bbcaa --- /dev/null +++ b/ROOT/exo7/cookie-form.html @@ -0,0 +1,13 @@ + + + +
+ First name:
+
+ Last name:
+

+ +
+ + + diff --git a/ROOT/exo7/nextpage.jsp b/ROOT/exo7/nextpage.jsp index 37153a6..f54b811 100644 --- a/ROOT/exo7/nextpage.jsp +++ b/ROOT/exo7/nextpage.jsp @@ -1,6 +1,9 @@ - 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")); %> diff --git a/ROOT/exo7/setcookie.jsp b/ROOT/exo7/setcookie.jsp new file mode 100644 index 0000000..43ffe8d --- /dev/null +++ b/ROOT/exo7/setcookie.jsp @@ -0,0 +1,16 @@ +<%@ 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); +%> + + + + Continue + + diff --git a/ROOT/exo7/viewcookie.jsp b/ROOT/exo7/viewcookie.jsp new file mode 100644 index 0000000..2a705f6 --- /dev/null +++ b/ROOT/exo7/viewcookie.jsp @@ -0,0 +1,13 @@ +<% Cookie[] cookies = request.getCookies(); %> + + + + Bonjour
+ <% + for(int i = 0; i < cookies.length; i++) { + Cookie c = cookies[i]; + out.println(c.getName() + " = " + c.getValue() + "
"); + } + %> + +