J'ai un problème pour afficher mes données provenant de la table membre sur ma page jsp.
Pourtant, à partir de mon controller, j'arrive à les afficher dans la console. Je pense que le problème se situe sur la transmission des données du controller vers la page web.
Fichier MembreDao
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class HibernateUtil { private static SessionFactory sessionFactory; public static SessionFactory getSessionFactory() { if(sessionFactory == null) { try { Configuration configuration = new Configuration(); Properties settings = new Properties(); settings.put(Environment.DRIVER, "com.mysql.jdbc.Driver"); settings.put(Environment.URL, "jdbc:mysql://localhost:3306/gestioncollaborative"); settings.put(Environment.USER, "root"); settings.put(Environment.PASS, ""); settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect"); settings.put(Environment.SHOW_SQL, "true"); settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); settings.put(Environment.HBM2DDL_AUTO, "update"); settings.put(Environment.AUTOCOMMIT, "true"); configuration.setProperties(settings); configuration.addAnnotatedClass(Membre.class); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; } catch (Exception e) { e.printStackTrace(); } } return sessionFactory; } }
MembreBean
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public class MembreDao { @SuppressWarnings("unchecked") public List<Membre> listeMembre() { List <Membre> listMembre = null; try(Session session = HibernateUtil.getSessionFactory().openSession()){ listMembre = session.createQuery("FROM membre").getResultList(); } catch(Exception e){ throw new RuntimeException(e); } return listMembre; } }
Mon Controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 @Entity @Table( name ="membre" ) public class Membre { @Id @GeneratedValue( strategy=GenerationType.IDENTITY ) @Column(name = "idmembre") private long id; private String nom; private String prenom; private String email; private String pass; private String photo; private LocalDate dateInscription; public Membre() {} public Membre(long pId, String pNom, String pPrenom, String pEmail, String pPass, String pPhoto, LocalDate pDate) { super(); this.setId(pId); this.setNom( pNom ); this.setPrenom( pPrenom ); this.setEmail( pEmail ); this.setPass(pPass); this.setPhoto( pPhoto ); this.setDate(pDate); } public Membre(String pNom, String pPrenom, String pEmail, String pPass, String pPhoto, LocalDate pDate) { super(); this.setNom( pNom ); this.setPrenom( pPrenom ); this.setEmail( pEmail ); this.setPass(pPass); this.setPhoto( pPhoto ); this.setDate(pDate); } public long getId() { return id; } public void setId(long pId) { this.id = pId; } 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 getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPhoto() { return photo; } public void setPhoto(String photo) { this.photo = photo; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public LocalDate getDate() { return dateInscription; } public void setDate(LocalDate now) { this.dateInscription = now; } }
Ma page jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 @SuppressWarnings("unused") public void init() { MembreDao membreDao = new MembreDao(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //doGet(request, response); List <Membre> listeMembre = membreDao.listeMembre(); request.setAttribute("listeMembre", listeMembre); RequestDispatcher dispatcher = request.getRequestDispatcher("listemembre.jsp"); dispatcher.forward(request, response); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <table class="table table-bordered" id="dataTable" width="100%"> <thead> <tr> <th>NOM ET PRENOM </th> <th>E-MAIL</th> <th>INSCRIS LE</th> </tr> </thead> <tbody> <c:forEach var="membre" items="${listeMembre}"> <tr> <td><c:out value="${membre.nom}" /> <c:out value="${membre.prenom}+" /></td> <td><c:out value="${membre.email}" /></td> <td><c:out value="${membre.dateinscription}" /></td> </tr> </c:forEach> </tbody> </table>
Partager