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>");
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Authentification</servlet-name>
<servlet-class>servlets.Authentification</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Bienvenue sur cet espace</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Authentification</servlet-name>
<url-pattern>/Accueil</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>Accueil</welcome-file>
</welcome-file-list>
</web-app>
1 / 2 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !