Add exo4 missing bits and exo10 code.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 11 Apr 2018 12:40:36 +0000 (14:40 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 11 Apr 2018 12:40:36 +0000 (14:40 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
16 files changed:
ROOT/exo10/WEB-INF/classes/date/Date.class [new file with mode: 0644]
ROOT/exo10/WEB-INF/classes/date/DateRefresh.class [new file with mode: 0644]
ROOT/exo10/WEB-INF/classes/form/Checkbox.class [new file with mode: 0644]
ROOT/exo10/WEB-INF/classes/form/Login.class [new file with mode: 0644]
ROOT/exo10/WEB-INF/classes/hello/HelloWorld.class
ROOT/exo10/WEB-INF/src/date/Date.java [new file with mode: 0644]
ROOT/exo10/WEB-INF/src/date/DateRefresh.java [new file with mode: 0644]
ROOT/exo10/WEB-INF/src/form/Checkbox.java [new file with mode: 0644]
ROOT/exo10/WEB-INF/src/form/Login.java [new file with mode: 0644]
ROOT/exo10/WEB-INF/src/hello/HelloWorld.java
ROOT/exo10/form.html [new file with mode: 0644]
ROOT/exo10/formcheckbox.html [new file with mode: 0644]
ROOT/exo4/WEB-INF/src/bonjour/hello.java [new file with mode: 0644]
ROOT/exo4/WEB-INF/web.xml [new file with mode: 0644]
ROOT/exo4/hello.jsp [new file with mode: 0644]
ROOT/exo7/cookie-form.html

diff --git a/ROOT/exo10/WEB-INF/classes/date/Date.class b/ROOT/exo10/WEB-INF/classes/date/Date.class
new file mode 100644 (file)
index 0000000..6e7c1ab
Binary files /dev/null and b/ROOT/exo10/WEB-INF/classes/date/Date.class differ
diff --git a/ROOT/exo10/WEB-INF/classes/date/DateRefresh.class b/ROOT/exo10/WEB-INF/classes/date/DateRefresh.class
new file mode 100644 (file)
index 0000000..8f1a417
Binary files /dev/null and b/ROOT/exo10/WEB-INF/classes/date/DateRefresh.class differ
diff --git a/ROOT/exo10/WEB-INF/classes/form/Checkbox.class b/ROOT/exo10/WEB-INF/classes/form/Checkbox.class
new file mode 100644 (file)
index 0000000..8858592
Binary files /dev/null and b/ROOT/exo10/WEB-INF/classes/form/Checkbox.class differ
diff --git a/ROOT/exo10/WEB-INF/classes/form/Login.class b/ROOT/exo10/WEB-INF/classes/form/Login.class
new file mode 100644 (file)
index 0000000..854675d
Binary files /dev/null and b/ROOT/exo10/WEB-INF/classes/form/Login.class differ
index 24e3e9716b89d97e743dce53351d464f3353f19e..ffc0db36374dc54ebae9f7cd6fd49fcd51483b8d 100644 (file)
Binary files a/ROOT/exo10/WEB-INF/classes/hello/HelloWorld.class and b/ROOT/exo10/WEB-INF/classes/hello/HelloWorld.class differ
diff --git a/ROOT/exo10/WEB-INF/src/date/Date.java b/ROOT/exo10/WEB-INF/src/date/Date.java
new file mode 100644 (file)
index 0000000..b29fab4
--- /dev/null
@@ -0,0 +1,43 @@
+package date;
+
+// Import required java libraries
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.WebServlet;
+
+@WebServlet(name="Date", urlPatterns={"/Date"})
+// Extend HttpServlet class
+public class Date extends HttpServlet {
+
+   private java.util.Date d;
+   private Integer count;
+
+   public void init() throws ServletException {
+      // Do required initialization
+      d = new java.util.Date(); // Date at init time, do not change
+      count = 0;
+   }
+
+   public void doGet(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+
+      // Set response content type
+      response.setContentType("text/html");
+
+      // Actual logic goes here.
+      count++;
+      PrintWriter out = response.getWriter();
+      out.println("<html>");
+      out.println("<body>");
+      out.println("Date " + d.toString());
+      out.println("<br>");
+      out.println("GET call number " + count);
+      out.println("</body>");
+      out.println("</html>");
+   }
+
+   public void destroy() {
+      count = 0;
+   }
+}
diff --git a/ROOT/exo10/WEB-INF/src/date/DateRefresh.java b/ROOT/exo10/WEB-INF/src/date/DateRefresh.java
new file mode 100644 (file)
index 0000000..24cbd5f
--- /dev/null
@@ -0,0 +1,44 @@
+package date;
+
+// Import required java libraries
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.WebServlet;
+
+@WebServlet(name="DateRefresh", urlPatterns={"/DateRefresh"})
+// Extend HttpServlet class
+public class DateRefresh extends HttpServlet {
+
+   //private java.util.Date d;
+   //private Integer count;
+
+   public void init() throws ServletException {
+      // Do required initialization
+      //d = new java.util.Date(); // DateRefresh at init time, do not change
+      //count = 0;
+   }
+
+   public void doGet(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+
+      // Set response content type
+      response.setContentType("text/html");
+      response.addHeader("Refresh", "1");
+
+      // Actual logic goes here.
+      //count++;
+      PrintWriter out = response.getWriter();
+      out.println("<html>");
+      out.println("<body>");
+      out.println("Date " + new java.util.Date().toString());
+      //out.println("<br>");
+      //out.println("GET call number " + count);
+      out.println("</body>");
+      out.println("</html>");
+   }
+
+   public void destroy() {
+      //count = 0;
+   }
+}
diff --git a/ROOT/exo10/WEB-INF/src/form/Checkbox.java b/ROOT/exo10/WEB-INF/src/form/Checkbox.java
new file mode 100644 (file)
index 0000000..7a55915
--- /dev/null
@@ -0,0 +1,42 @@
+package form;
+
+// Import required java libraries
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.WebServlet;
+
+@WebServlet(name="Checkbox", urlPatterns={"/Checkbox"})
+// Extend HttpServlet class
+public class Checkbox extends HttpServlet {
+
+   private String[] players;
+
+   public void init() throws ServletException {
+      // Do required initialization
+        players = new String[4];
+      }
+
+   public void doPost(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+
+      // Set response content type
+      response.setContentType("text/html");
+
+      String[] players = request.getParameterValues("player");
+
+      // Actual logic goes here.
+      PrintWriter out = response.getWriter();
+      out.println("<html>");
+      out.println("<body>");
+      for (int i = 0; i < players.length; i++) {
+          out.println(players[i] + "<br>");
+      }
+      out.println("</body>");
+      out.println("</html>");
+   }
+
+   public void destroy() {
+
+   }
+}
diff --git a/ROOT/exo10/WEB-INF/src/form/Login.java b/ROOT/exo10/WEB-INF/src/form/Login.java
new file mode 100644 (file)
index 0000000..4f4f8d1
--- /dev/null
@@ -0,0 +1,63 @@
+package form;
+
+// Import required java libraries
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.WebServlet;
+
+@WebServlet(name="Login", urlPatterns={"/Login"})
+// Extend HttpServlet class
+public class Login extends HttpServlet {
+
+   private String login;
+   private String password;
+
+   public void init() throws ServletException {
+      // Do required initialization
+      login = new String();
+      password = new String();
+   }
+
+   public void doGet(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+
+      // Set response content type
+      response.setContentType("text/html");
+
+      // Actual logic goes here.
+      login = request.getParameter("login");
+      password = request.getParameter("password");
+      PrintWriter out = response.getWriter();
+      out.println("<html>");
+      out.println("<body>");
+      out.println("Login: " + login);
+      out.println("<br>");
+      out.println("Password: " + password);
+      out.println("</body>");
+      out.println("</html>");
+   }
+
+   public void doPost(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+
+      // Set response content type
+      response.setContentType("text/html");
+
+      // Actual logic goes here.
+      login = request.getParameter("login");
+      password = request.getParameter("password");
+      PrintWriter out = response.getWriter();
+      out.println("<html>");
+      out.println("<body>");
+      out.println("Login: " + login);
+      out.println("<br>");
+      out.println("Password: " + password);
+      out.println("</body>");
+      out.println("</html>");
+   }
+
+   public void destroy() {
+
+   }
+}
index 446f823af501513ea58cc029a41d4a6e1e434fb3..f25597f8f63ee6b3fd35a3c7f43b928a2c8b7e96 100644 (file)
@@ -14,7 +14,7 @@ public class HelloWorld extends HttpServlet {
 
    public void init() throws ServletException {
       // Do required initialization
-      message = "Hello World";
+      message = "Bienvenue au cours d'applications Web";
    }
 
    public void doGet(HttpServletRequest request, HttpServletResponse response)
diff --git a/ROOT/exo10/form.html b/ROOT/exo10/form.html
new file mode 100644 (file)
index 0000000..087835a
--- /dev/null
@@ -0,0 +1,14 @@
+<meta charset="UTF-8">
+<html>
+<body>
+
+<form method="POST" action="/Login">
+  Login:<br>
+  <input type="text" name="login"><br>
+  Password:<br>
+  <input type="password" name="password"><br><br>
+  <input type="submit" value="Submit">
+</form>
+
+</body>
+</html>
diff --git a/ROOT/exo10/formcheckbox.html b/ROOT/exo10/formcheckbox.html
new file mode 100644 (file)
index 0000000..afc6e0d
--- /dev/null
@@ -0,0 +1,19 @@
+<meta charset="UTF-8">
+<html>
+<body>
+
+<form method="POST" action="/Checkbox">
+  Quel joueur préférez-vous ?<br>
+  <input type="checkbox" id="Zidane" name="player" value="Zidane">
+  <label for="Zidane">Zidane</label><br>
+  <input type="checkbox" id="Maradona" name="player" value="Maradona">
+  <label for="Maradona">Maradona</label><br>
+  <input type="checkbox" id="Platini" name="player" value="Platini">
+  <label for="Platini">Platini</label><br>
+  <input type="checkbox" id="Pelé" name="player" value="Pelé">
+  <label for="Pelé">Pelé</label><br><br>
+  <input type="submit" value="Submit">
+</form>
+
+</body>
+</html>
diff --git a/ROOT/exo4/WEB-INF/src/bonjour/hello.java b/ROOT/exo4/WEB-INF/src/bonjour/hello.java
new file mode 100644 (file)
index 0000000..9970d64
--- /dev/null
@@ -0,0 +1,7 @@
+package bonjour;
+
+public class hello {
+    public String affiche() {
+        return "Bonjour";
+    }
+}
diff --git a/ROOT/exo4/WEB-INF/web.xml b/ROOT/exo4/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..7f339c8
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+  version="3.1">
+
+</web-app>
diff --git a/ROOT/exo4/hello.jsp b/ROOT/exo4/hello.jsp
new file mode 100644 (file)
index 0000000..11fcb52
--- /dev/null
@@ -0,0 +1,9 @@
+<%@ page import="bonjour.hello, javax.servlet.*" %>
+<html>
+<body>
+<%
+    hello h = new hello();
+    //out.print(h.afficher());
+%>
+</body>
+</html>
index 10bbcaa018d59192e0293ac2311ba8747f096788..aba78e800654f9b0454979d7ea5d347e829aa219 100644 (file)
@@ -1,3 +1,4 @@
+<meta charset="UTF-8">
 <html>
 <body>