Affichage Tableau dans JSP
Bonjour à tous,
J'ai besoin d'aide car ça fait une semaine que je galère sur même le problème, je vous explique. Alors voilà je voudrais afficher un tableau de données dans une page JSP qui m'afficherait le contenu de ma table dans ma base de données. Via le mode console j'ai bien vérifié que je récupère en objet les données que contient ma table dans la base de données, le problème c'est que ces données ne s'affichent pas dans ma JSP et là je suis à court d'idées pouvez-vous regarder mon code s'il vous plaît pour voir s'il y a quelque chose qui ne va pas ?
Le modèle
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
public class ClientInscriptionEntity {
private String nom;
private String prenom;
private String adresse;
private String ville;
private String code_postal;
private String telephone;
private String mail;
private String login;
private String password;
public ClientInscriptionEntity(String nom, String prenom, String adresse,
String ville, String code_postal, String telephone, String mail,
String login, String password) {
super();
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
this.ville = ville;
this.code_postal = code_postal;
this.telephone = telephone;
this.mail = mail;
this.login = login;
this.password = password;
}
public ClientInscriptionEntity() {
super();
// TODO Auto-generated constructor stub
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public String getVille() {
return ville;
}
public void setVille(String ville) {
this.ville = ville;
}
public String getCode_postal() {
return code_postal;
}
public void setCode_postal(String code_postal) {
this.code_postal = code_postal;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "ClientInscriptionEntity [nom=" + nom + ", prenom=" + prenom
+ ", adresse=" + adresse + ", ville=" + ville
+ ", code_postal=" + code_postal + ", telephone=" + telephone
+ ", mail=" + mail + ", login=" + login + ", password="
+ password + "]";
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClientInscriptionEntity other = (ClientInscriptionEntity) obj;
if (login == null) {
if (other.login != null)
return false;
} else if (!login.equals(other.login))
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
return true;
}
} |
Le bean
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import java.util.ArrayList;
import Modele.ClientInscriptionEntity;
public class ClientInscriptionBeans {
private ClientInscriptionEntity client = new ClientInscriptionEntity();
private ArrayList <ClientInscriptionEntity> liste = new ArrayList<ClientInscriptionEntity>();
public ClientInscriptionEntity getClient() {
return client;
}
public void setClient(ClientInscriptionEntity client) {
this.client = client;
}
public ArrayList<ClientInscriptionEntity> getListe() {
return liste;
}
public void setListe(ArrayList<ClientInscriptionEntity> liste) {
this.liste = liste;
}
} |
Le DAO
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
package DAO_Entity;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import Modele.ClientInscriptionEntity;
public class DAO_AgentAdmin {
/**
* Recherche une instance depuis la base de données à partir de l'identifiant
*
* @param con
* @param id
* @return l'instance
* @throws SQLException
*/
public ArrayList<ClientInscriptionEntity> demande_client = new ArrayList<ClientInscriptionEntity>();
public ArrayList<ClientInscriptionEntity> getDemande_client() {
return demande_client;
}
public void setDemande_client(ArrayList<ClientInscriptionEntity> demande_client) {
this.demande_client = demande_client;
}
public ArrayList getAll() {
ArrayList liste_demande = new ArrayList<ClientInscriptionEntity>();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/agora","root", "");
PreparedStatement pr = cn.prepareStatement("SELECT * FROM client_inscription ");
ResultSet rs = pr.executeQuery();
while (rs.next()) {
ClientInscriptionEntity demande_client = new ClientInscriptionEntity();
demande_client.setNom(rs.getString("nom"));
demande_client.setPrenom(rs.getString("prenom"));
demande_client.setAdresse(rs.getString("adresse"));
demande_client.setVille(rs.getString("ville"));
demande_client.setCode_postal(rs.getString("code_postal"));
demande_client.setTelephone(rs.getString("telephone"));
demande_client.setMail(rs.getString("mail"));
demande_client.setLogin(rs.getString("login"));
demande_client.setPassword(rs.getString("password"));
System.out.println("objet" + demande_client.toString() + "/n"+ "bd"+ rs.getString("nom"));
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
return liste_demande;
}
} |
Le Servlets
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
import java.io.IOException;
import java.sql.Connection;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Beans.ClientInscriptionBeans;
import DAO_Entity.DAO_AgentAdmin;
@WebServlet(name = "Traitement_demande_inscription", urlPatterns = { "/Traitement_demande_inscription" })
public class Traitement_demande_inscription extends HttpServlet {
/**
* @see HttpServlet#HttpServlet()
*/
private static final long serialVersionUID = 1L;
public Traitement_demande_inscription() {
super();
// TODO Auto-generated constructor stub
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Connection con = null;
DAO_AgentAdmin dao_admin = new DAO_AgentAdmin();
// // Récupère les informations
// String nom = req.getParameter("nom");
// String prenom = req.getParameter("prenom");
// String adresse = req.getParameter("adresse");
// String ville = req.getParameter("ville");
// String code_postal = req.getParameter("code_postal");
// String telephone = req.getParameter("telephone");
// String mail = req.getParameter("mail");
// String login = req.getParameter("login");
// String password = req.getParameter("password");
ClientInscriptionBeans cl_inscription = new ClientInscriptionBeans();
cl_inscription.setListe(dao_admin.getAll());
//String tableau [] = tableau;
req.setAttribute("tableau", cl_inscription);
req.getRequestDispatcher("page_agent_admin.jsp").forward(req, resp);
// try {
// con = ConnexionBD.getInstance();
// System.out.println("conection réussie");
// if (!ConnexionBD.isValide()) {
// throw new ConnexionException(
// "Probleme de connexion au serveur.");
// }
// } catch (ConnexionException e) {
// System.out.println(e.getMessage());
// System.exit(1);
// }
}
} |
Mon web.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Connexion</servlet-name>
<servlet-class>Servlets.Connexion</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Connexion</servlet-name>
<url-pattern>/con</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Traitement_demande_inscription</servlet-name>
<servlet-class>Servlets.Traitement_demande_inscription</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Traitement_demande_inscription</servlet-name>
<url-pattern>/agent</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>InscriptionClient</servlet-name>
<servlet-class>Servlets.InscriptionClient</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InscriptionClient</servlet-name>
<url-pattern>/inscription</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Internaute</servlet-name>
<servlet-class>Servlets.Internaute</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Internaute</servlet-name>
<url-pattern>/internaute</url-pattern>
</servlet-mapping>
<!-- <display-name>Agora2015</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> -->
</web-app> |
Et ma page JSP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<%@page import="Beans.ClientInscriptionBeans"%>
<%@page import="Modele.ClientInscriptionEntity"%>
<%@page import="DAO_Entity.DAO_AgentAdmin"%>
<%@page import="java.util.Iterator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Acceuil Agent Administratif</title>
</head>
<body>
<%
ClientInscriptionBeans client = (ClientInscriptionBeans) request.getAttribute("tableau");
if(request.getAttribute("tableau") != null){
client = (ClientInscriptionBeans) request.getAttribute("tableau");
} else {
DAO_AgentAdmin admin = new DAO_AgentAdmin();
client = new ClientInscriptionBeans();
client.setListe(admin.getAll());
}
%>
<div id="header">
<font size=100 face="gabriola" style="text-align:center;"> Acceuil Agent Administratif </font>
</div>
<h3>Demande d'inscription des clients</h3>
<form action="agent" method="post">
</form>
<table border="1" width="30%" >
<tr>
<th>Nom</th>
<th>Prenom</th>
<th>Adresse</th>
<th>Ville</th>
<th>Code Postal</th>
<th>Telephone</th>
<th>Mail</th>
<th>Login</th>
<th>Password</th>
</tr>
<%
Iterator <ClientInscriptionEntity> list = client.getListe().iterator();
while(list.hasNext()){
ClientInscriptionEntity cl = list.next();
%>
<tr>
<td><%=cl.getNom() %></td>
<td><%=cl.getPrenom() %></td>
<td><%=cl.getAdresse() %></td>
<td><%=cl.getVille() %></td>
<td><%=cl.getCode_postal() %></td>
<td><%=cl.getTelephone() %></td>
<td><%=cl.getMail() %></td>
<td><%=cl.getLogin() %></td>
<td><%=cl.getPassword() %></td>
<td>
<form action="agent" method="post">
<input type="hidden" name="id" value="<%=cl.getMail() %>" >
<input type="hidden" name="action" value="Supprimer" >
<input type="submit" value="Supprimer" />
</form>
</td>
</tr>
<% } %>
</table>
</body>
</html> |