Bonjour a tout , j’ai un petit problème avec les javabean , j’ai créé une jsp «BeanTest.jsp » dans laquelle un formulaire envoi les données saisie vers une autre page « BeanTest_action.jsp » cette dernière utilise un bean pour récupérer les données saisie et elle les insère dans une base de données acces puis elle fait une redirection vers la première page «BeanTest.jsp » ou j’affiche l’ensemble de données insérer dans la table , mais chaque fois que j’ajoute une nouvelle ligne elle ne s’affiche pas qu’après que j’actualise la page manuellement , voila le code source et merci pour toute aide.
BeanTest.jsp
BeanTest_action.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
SimpleBean.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
2
3
4
5
6
7
8
9
10
11
Conection.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
93package bean; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Vector; import dataaccess.Conection; public class SimpleBean { private String id = ""; private String nom = ""; private String prenom = ""; private String login = ""; private String password = ""; private String profil = ""; public String getId() { return (id); } public void setId(String id) { this.id = id; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getProfil() { return profil; } public void setProfil(String profil) { this.profil = profil; } public void ajoutPers() throws ClassNotFoundException, SQLException { Connection connexion = Conection.getConn(); Statement requete = connexion.createStatement(); int i = requete.executeUpdate("insert into personne values(" + this.id + ",'" + this.nom + "','" + this.prenom + "','" + this.profil + "','" + this.login + "','" + this.password + "')"); } public static Vector getPers() throws ClassNotFoundException, SQLException { Vector vect = new Vector(); Connection connexion = Conection.getConn(); Statement requete = connexion.createStatement(); ResultSet resultat = requete.executeQuery("SELECT * FROM personne order by id;"); boolean encore = resultat.next (); while (encore) { String[] tab = new String[6]; tab[0]= resultat.getInt(1)+""; tab[1]= resultat.getString(2); tab[2]= resultat.getString(3); tab[3]= resultat.getString(4); tab[4]= resultat.getString(5); tab[5]= resultat.getString(6); vect.addElement(tab); encore = resultat.next (); } return vect; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
42package dataaccess; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Conection { public static Connection getConn() throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:db1"; Connection connexion = DriverManager.getConnection(url, "test", "test"); return connexion; } public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:db1"; Connection connexion = DriverManager.getConnection(url, "test", "test"); Statement requete = connexion.createStatement(); int i = requete.executeUpdate("insert into personne values(4,'bouslimi','atef','admin','fghfg','hfg')"); System.out.println("i = "+i); ResultSet resultat = requete.executeQuery("SELECT DISTINCT nom FROM personne order by nom;"); boolean encore = resultat.next (); while (encore) { /* Pour lire et afficher toutes les colonnes en tabulant */ System.out.print(resultat.getString(1)); encore = resultat.next (); } } }
Modéré par zekey: Ajout des balises code, s'il vous plait pensez-y

 

 
		
		 
        

 
			
			
 
   



 
				 jsp et javabean
 jsp et javabean
				 Répondre avec citation
  Répondre avec citation


 
			 
 
Partager