Salut les Javatiens,
pour une fois c'est moi qui vient demander de l'aide dans un techno que je commence à apprendre (je suis plus orienté Laravel et PHP).
Je créais un Site Web avec J2E, en mode MVC pour la gestion d'un loueur (servlet + JSP).
J'ai une classe qui reflet un objet Bien:
Code Java : 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 package com.business; public class Bien { private int id_bien; private String adresse; private String codepostal; private String ville; private String etage; private int nature_id; public Bien() { } public Bien( int id_bien, String adresse, String codepostal, String ville, String etage, int nature_id) { this.setIdBien(id_bien); this.setAdresse(adresse); this.setCodePostal(codepostal); this.setVille(ville); this.setEtage(etage); this.setNatureId(nature_id); } public int getIdBien() { return id_bien; } public void setIdBien( int id_bien) { this.id_bien = id_bien; } public String getAdresse() { return adresse; } public void setAdresse(String adresse) { this.adresse = adresse; } public String getCodePostal () { return codepostal; } public void setCodePostal (String codepostal) { this.codepostal = codepostal; } public String getVille() { return ville; } public void setVille(String ville) { this.ville = ville; } public String getEtage() { return etage; } public void setEtage (String etage) { this.etage = etage; } public int getNatureId() { return nature_id; } public void setNatureId(int nature_id) { this.nature_id = nature_id; } public String getNature(int nature_id) { String nature = null; return nature; } }
J'ai une class avec les fonctions pour aller chercher mes élèments en DB:
Code Java : 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 package com.connector.dao; import java.sql.*; import java.util.ArrayList; import java.util.List; import com.business.Bien; public class BienDAO extends DAOContext { public static int getBienCount() { try (Connection connection = DriverManager.getConnection(dbURL, dbLogin, dbPassword)) { String strSQL = "SELECT COUNT(id_bien) FROM bien"; try ( Statement statement = connection.createStatement()) { try ( ResultSet resultSet = statement.executeQuery(strSQL)) { resultSet.next(); return resultSet.getInt(1); } } } catch ( Exception exception) { throw new RuntimeException (exception); } } public List<Bien> getListBien() { List<Bien> biens = new ArrayList<Bien>(); try (Connection connection = DriverManager.getConnection(dbURL, dbLogin, dbPassword)) { String strSQL = "SELECT * FROM bien"; try ( Statement statement = connection.createStatement()) { try ( ResultSet resultSet = statement.executeQuery(strSQL)) { while(resultSet.next()) { Bien bien = new Bien( resultSet.getInt("id_bien"), resultSet.getString("adresse"), resultSet.getString("codepostal"), resultSet.getString("ville"), resultSet.getString("etage"), resultSet.getInt("nature_id")); biens.add(bien); } } } } catch ( Exception exception) { throw new RuntimeException (exception); } return biens; } }
J'ai ma Servlet ListBien :
Code Java : 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 package com.servlet.ihm; import java.io.IOException; 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 com.business.Bien; import com.connector.dao.BienDAO; import com.connector.dao.DAOContext; /** * Servlet implementation class ListeBien */ @WebServlet("/listeBien") public class ListeBien extends HttpServlet { private static final long serialVersionUID = 1L; public void init() throws ServletException { DAOContext.init(getServletContext()); } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("page_name", "Gestion des Biens"); BienDAO listBien = new BienDAO(); request.setAttribute("data_biens", listBien.getListBien()); request.setAttribute("nblignedata", listBien.getListBien().size()); for (int i = 0; i < listBien.getListBien().size() ; i++) { System.out.println(listBien.getListBien().get(i).getIdBien()); System.out.println(listBien.getListBien().get(i).getAdresse()); System.out.println(listBien.getListBien().get(i).getCodePostal()); System.out.println(listBien.getListBien().get(i).getVille()); System.out.println(listBien.getListBien().get(i).getEtage()); System.out.println(listBien.getListBien().get(i).getNatureId()); } request.getRequestDispatcher("/listebien.jsp").forward(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
Et pour fini ma vue listebien.jsp
L'erreur est la suivante :
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 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <link href="library/css/style.css" rel="stylesheet"> <meta charset="UTF-8"> <title>Gestion du CROUS - ${page_name}</title> </head> <body> <div class="wrapper"> <header class="main-header"><%@ include file="library/layout/header.jsp" %></header> <nav class="main-sidebar"><%@ include file="library/layout/left_main.jsp" %></nav> <section class="content"> <table> <thead> <tr> <th>Identifiant</th> <th>Adresse</th> <th>Ville</th> <th>Code postal</th> <th>Etage</th> <th>Nature</th> </tr> </thead> <tbody> <c:forEach items="${data_biens}" var="listBiens"> <tr> <td>${listBiens.id_bien }</td> <td>${listBiens.adresse }</td> <td>${listBiens.ville }</td> <td></td> <td>${listBiens.etage }</td> <td></td> </tr> </c:forEach> </tbody> <tfoot></tfoot> </table> </section> <footer class="main-footer"><%@ include file="library/layout/footer.jsp" %></footer> </div> </body> </html>
cette erreur ne survient que quand j'essaye d'afficher l'id du bien, le code postal ou la nature id depuis l'attribut transmit par request.
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 Type Rapport d'exception message Une exception s'est produite lors du traitement de[/listebien.jsp] à la ligne [29] description Le serveur a rencontré une erreur interne qui l'a empêché de satisfaire la requête. exception org.apache.jasper.JasperException: Une exception s'est produite lors du traitement de[/listebien.jsp] à la ligne [29] 26: <tbody> 27: <c:forEach items="${data_biens}" var="listBiens"> 28: <tr> 29: <td>${listBiens.id_bien }</td> 30: <td>${listBiens.adresse }</td> 31: <td>${listBiens.ville }</td> 32: <td></td> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:618) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:515) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) com.servlet.ihm.ListeBien.doGet(ListeBien.java:44) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) cause mère javax.el.PropertyNotFoundException: La propriété [id_bien] n'a pas été trouvée sur le type [com.business.Bien] javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:271) javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:223) javax.el.BeanELResolver.property(BeanELResolver.java:344) javax.el.BeanELResolver.getValue(BeanELResolver.java:95) org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104) org.apache.el.parser.AstValue.getValue(AstValue.java:184) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:954) org.apache.jsp.listebien_jsp._jspx_meth_c_005fforEach_005f0(listebien_jsp.java:191) org.apache.jsp.listebien_jsp._jspService(listebien_jsp.java:136) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) com.servlet.ihm.ListeBien.doGet(ListeBien.java:44) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de ce serveur.
J'ai fait une boucle dans la Servlet, avec l'appel d'objet en sortie de console et la je n'ai pas de probleme.
J'ai un peu de mal à comprendre pourquoi cette champs et pas d'autres.
Merci pour votre aide
Partager