Bonjour,
j'ai une application 3 tiers
JSP - EJB - JPA.
J'ai une table dans ma bd "Groupe".
J'ai crée côté JPA, une entité
côté présentation :
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 import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @Entity public class Groupe implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int idgroupe; private String nom; private String photo; private String email; @Lob private String valide; @Lob private String informations; private static final long serialVersionUID = 1L; public Groupe() { super(); } public int getIdgroupe() { return this.idgroupe; } public void setIdgroupe(int idgroupe) { this.idgroupe = idgroupe; } public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } public String getPhoto() { return this.photo; } public void setPhoto(String photo) { this.photo = photo; } public String getEmail() { return this.email; } public void setEmail(String email) { this.email = email; } public String getValide() { return this.valide; } public void setValide(String valide) { this.valide = valide; } public String getInformations() { return this.informations; } public void setInformations(String informations) { this.informations = informations; } }
j'utilise une classe bean :
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
31import java.util.List; import javax.ejb.EJB; import javax.naming.InitialContext; import javax.naming.NamingException; import sample.SimpleBean; import table.Genre; import table.Groupe; public class TestBean { SimpleBean bean; public TestBean() throws NamingException{ InitialContext ctx = new InitialContext(); this.bean = (SimpleBean) ctx.lookup("ejb/SimpleBeanJNDI"); } public List<Genre> getFindGenre(){ return this.bean.getFindGenre(); } public void setCreerGroupe(Groupe g){ this.bean.createGroupe(g); } }
j'arrive à récuperer les différents genre du groupe
côté 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 <jsp:useBean id="Example" class="pojo.TestBean" scope="request"/> <form id="form1" method="post" action="valider.jsp"> <div class="entry"> <div style="float:left">Nom du groupe</div><div><input type="text" name="nom"></div> <div style="float:left">Email du groupe</div><div><input type="text" name="email"></div> <div style="float:left">Choix du genre</div><div> <p> <label> <jsp:useBean id="Example" class="pojo.TestBean" scope="request"/> <select name="genreGroupe"> <c:forEach var="genre" items="${Example.findGenre}"> <option> <c:out value="${genre.nom}"/> </option> </c:forEach> </select> <input type="submit" value="Valider" name="valider"> </label> </p> </form>
j'ai envie d'ajouter un groupe dans ma bd mais je sais pas comment faire en JSP (ça marche en utilisant des scriplets et mettre du code java en dure)
en gros, j'aimerai faire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Groupe g = new Groupe(); g.setNom(request.getParameter("nom"); bean.setCreerGroupe(g) etc.... mais sans utiliser du code java, juste avec JSP
Partager