Bonjour a tous,
mon pb consiste lors de l'extraction des données de BD. en faite, à l'aide des log j'ai pu contrôler que les données sont biens captées et sont bien correctes mais j'ai pas pu les exploiter dans ma page JSP.(on dirait que je suis entrain d'appeler une fausse bean ou j'ai pas déclarer la bean...)
le code de bean.java:
le code de la page de login.jsp :
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
96
97
98 package beanPackage; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Session; import org.hibernate.Transaction; public class Bean1 { Logger log = Logger.getLogger(this.getClass().getName()); private int id; private String name; private String pwd; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String login1() { String S="lol"; String X="rr"; if(name.isEmpty()) { S="login"; X="name vide"; } else if(pwd.isEmpty()) { S="login"; X="pwd vide"; } else S="formation"; System.out.println(X); return (S);} public String yyy(){ Session session = null; String S=null; if(name.isEmpty()){ S="rejected"; } else { session = HibernateSessionFactory.currentSession(); Transaction tx = session.beginTransaction(); Bean1 user=new Bean1(); //user.setId(9); //user.setId(4); user.setName(this.name); user.setPwd(this.pwd); session.save(user); tx.commit(); List users = session.createQuery("select u from Bean1 as u ") .list(); log.info("list users"); for (Iterator iter = users.iterator(); iter.hasNext();) { Bean1 element = (Bean1) iter.next(); log.info(element.getName()+element.getPwd()); } S="accepted"; } return S ; } public String capDonnées() { Session session = null; String S=null; session= HibernateSessionFactory.currentSession(); Transaction tx = session.beginTransaction(); Bean1 user1 =null; user1= new Bean1(); List user= session.createQuery("from Bean1 u where u.id=7").list(); user1=(Bean1) user.get(0); log.info(user1.getName()); log.info(user1.getPwd()); S="mmm"; return S ; } }
et le code de la page mmm.jsp
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 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="html" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title> Amed GP</title> </head> <body> <br> <center> <h2> HOME </h2><br><br> <core:view> <html:form> <h2> <html:outputText value="Authentification"></html:outputText> </h2><br><br> <html:outputLabel value="Login"></html:outputLabel> <html:inputText size="20" value="#{bean1.name}"></html:inputText> <br> <html:outputLabel value="Password"></html:outputLabel> <html:inputSecret size="20" value="#{bean1.pwd}"></html:inputSecret><br> <html:commandButton value="Save" action="#{bean1.yyy}"></html:commandButton> <html:commandButton value="Récupérer" action="#{bean1.capDonnées}"></html:commandButton> </html:form> </core:view> </center> </body> </html>
et merci d'avance..
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 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="html" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title> Les valeurs Extraites </title> </head> <body> <core:view> <h1> <html:outputText value="Valeurs "></html:outputText> </h1> <br> <h3> <html:outputText value="#{bean1.name}"></html:outputText> </h3> <br> <html:outputText value="#{bean1.pwd}"></html:outputText><br> </core:view> </body> </html>
Partager