TP1 – corrigé
Authentification.java
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Daniel Enselme
*/
public class Authentification extends HttpServlet {
String message=null;
public void init() throws ServletException{
ServletConfig config = getServletConfig();
message = config.getInitParameter("message");
}
protected void doGet
(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head>");
out.println("<title>E-421</title><hr>");
out.println("<title>Le jeu du 421</title>");
out.println("</head><body>");
out.println("<h4>"+message+"</h4><hr>");
out.println("<form name='login' action='' method='post'>");
out.println("<h4>Nom : </h4>");
out.println(" <input name='nom' type='text' value='Votre nom' >");
out.println("<br><br>");
out.println(" <input name='' type='submit' value='valider'>");
out.println("</form>");
out.println("</body><html>");
}
protected void doPost
(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String nom = request.getParameter("nom");
out.println("<html><head>");
out.println("<title><h2>E-421</h2></title><hr>");
out.println("</head><body>");
out.println("<h4>"+message+"</h4><hr>");
out.println("<h4>Bonjour Mr "+nom+"</h4>");
out.println("<form name='login' action='' method='get'>");
out.println(" <input name='' type='submit' value='continuer'>");
out.println("</form>");
out.println("</body><html>");
}
}