Bonjour,
je poursuis ma d�couverte de ces nouvelles technos avec une nouvelle question. Je dispose d'une page FicheAbonne.jsp qui correspond � remplir diff�rents champs pour un abonn� (nom, prenom ...). Cette page contient un bouton de sauvegarde des informations dont certaines ne doivent pas �tre vides. Quand les informations sont correctement renseign�es, l'enregistrement est bien pris en compte (je ne fais pour le moment que de la modification d'enregistrement). En revanche, quand un champ est non rempli (par exemple le nom), la page est r�affich�e (par ma servlet) mais des champs ont maintenant la valeur null (les champs en disabled) ou les checkbox se d�cochent. Je vous mets ci-dessous ma servlet et ma page JSP.
Si l'un d'entre vous a une id�e ou une question, n'h�sitez pas.
Merci d'avance
Servlet :
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
99
100
101
102
103
104
105
106 package servlet; import java.io.IOException; import java.util.Iterator; import java.util.Vector; import hibernate.*; import hibernateMain.HibernateUtil; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.swing.JOptionPane; public class ServletAbonne extends HttpServlet { /** * */ private static final long serialVersionUID = -559546873832531359L; // paramètres d'instance public static Vector<Abonne> v; public static Session session; // init public void init() { session = HibernateUtil.currentSession(); Query myQuery = session.createQuery("From Abonne"); List result = myQuery.list(); v = new Vector<Abonne>(); for (Iterator it = result.iterator(); it.hasNext();) { v.addElement((Abonne) it.next()); } } //GET /*public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { }*/ /** * @param request la requête HTTP du client * @param response la réponse HTTP qu'on va construire */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // on passe la main au GET //doGet(request, response); String id = request.getParameter("txtId"); String nom = request.getParameter("txtNom"); String prenom = request.getParameter("txtPrenom"); String pwd = request.getParameter("txtPwd"); String user = request.getParameter("txtUser"); String telephone = request.getParameter("txtTelephone"); String mail = request.getParameter("txtMail"); String competences = request.getParameter("txtCompetences"); String actif= request.getParameter("ckActif"); String admin= request.getParameter("ckAdmin"); String datecreation= request.getParameter("txtDateCreation"); if (!(nom.equals("")) && !(prenom.equals("")) && !(pwd.equals("")) && !(user.equals(""))) { // Message de confirmation de la sauvegarde Transaction tx = session.beginTransaction(); Abonne abonne = (Abonne) session.load(Abonne.class, new Integer(id)); abonne.setAbonneUser(user); abonne.setAbonnePwd(pwd); abonne.setAbonneNom(nom); abonne.setAbonnePrenom(prenom); abonne.setAbonneTelephone(telephone); abonne.setAbonneMail(mail); abonne.setAbonneCompetences(competences); abonne.setAbonneMail(admin); abonne.setAbonneCompetences(actif); abonne.setAbonneMail(mail); abonne.setAbonneCompetences(competences); session.save(abonne); tx.commit(); //JOptionPane.showMessageDialog(null,"Abonné enregistré !"); System.out.println("L'abonné est bien enregistré"); getServletContext().getRequestDispatcher("/JSP/Abonne.jsp").forward(request,response); } else { // Message d'erreur : Abonné non sauvegardé System.out.println("Veuillez remplir les champs User, Password, Nom et Prenom !"); getServletContext().getRequestDispatcher("/JSP/FicheAbonne.jsp").forward(request,response); } } }
Ma page FicheAbonne.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
99
100
101
102
103 <%@ page language="Java" %> <% // on récupère les données nom, age et urlRetour nécessaire à l'affichage de la page String id=(String)request.getParameter("txtId"); String user=(String)request.getParameter("txtUser"); String pwd=(String)request.getParameter("txtPwd"); String nom=(String)request.getParameter("txtNom"); String prenom=(String)request.getParameter("txtPrenom"); String telephone=(String)request.getParameter("txtTelephone"); String mail=(String)request.getParameter("txtMail"); String competences=(String)request.getParameter("txtCompetences"); String actif=(String)request.getParameter("ckActif"); String admin=(String)request.getParameter("ckAdmin"); String datecreation=(String)request.getParameter("txtDateCreation"); System.out.println(datecreation+" "+admin); %> <html> <head> <title>Fiche de l'abonné</title> <LINK REL="StyleSheet" HREF="./../CSS/styles.css" TYPE="text/css"> </head> <body> <% String repass = request.getParameter("alreadypassed"); %> <% if (repass != null) { out.print ("<p align=\"center\">Veuillez remplir les champs User, Password, Nom et Prenom !</p>"); } %> <center> <h2>Fiche de l'abonné</h2> <hr> <form action="<%=request.getContextPath()+"/ServletAbonne"%>" method="post"> <table> <tr> <td>User*</td> <td><input name="txtUser" value="<%=user%>" type="text" size="20"></td> </tr> <tr> <td>Password*</td> <td><input name="txtPwd" value="<%=pwd%>" type="password" size="20"></td> </tr> <tr> <td>Nom*</td> <td><input name="txtNom" value="<%=nom%>" type="text" size="20"></td> </tr> <tr> <td>Prenom*</td> <td><input name="txtPrenom" value="<%=prenom%>" type="text" size="20"></td> </tr> <tr> <td>Telephone</td> <td><input name="txtTelephone" value="<%=telephone%>" type="text" size="10"></td> </tr> <tr> <td>Mail</td> <td><input name="txtMail" value="<%=mail%>" type="text" size="60"></td> </tr> <tr> <td>Competences</td> <td><input name="txtCompetences" value="<%=competences%>" type="text" size="100"></td> </tr> <tr> <td> <%if (admin.equals("1")) { %> <input type="checkbox" name="ckAdmin" checked="checked">Admin ? <% } else { %> <input type="checkbox" name="ckAdmin">Admin ? <% } %> </td> </tr> <tr> <td> <%if (actif.equals("1")) { %> <input type="checkbox" name="ckActif" checked="checked">Actif ? <% } else { %> <input type="checkbox" name="ckActif">Actif ? <% } %> </td> </tr> <tr> <td>Date de création</td> <td><input name="txtDateCreation" value="<%=datecreation%>" type="text" size="10" ></td> </tr> <tr></tr> <tr> <td>* Champs obligatoires</td> </tr> </table> <table> <tr> <td><input type="hidden" value="<%=id %>" name="txtId"></td> <td><input type="hidden" value="0" name="alreadypassed"></td> <td><input type="submit" value="Sauvegarder l'abonné"></td> </tr> </table> </form> </center> </body> </html>
Partager