Bonjour voici mon probleme je veux que quand je clic sur le bouton confirmer un message d'alerte s'affiche qui m'indique si ma carte à bien été ajouté ou non voici mon interface :






Nom : openclassroom1.PNG
Affichages : 35
Taille : 37,5 Ko


voici le code de ma page jsp :



Code jsp : 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="Controllers.cnx"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
 
<%
 
Connection c=cnx.getcnx();
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from liaison_taxe_modulaire");
Statement st1=c.createStatement();
ResultSet rs1=st1.executeQuery("select * from liaison_taxe_modulaire");
Statement st2=c.createStatement();
ResultSet rs2=st2.executeQuery("select * from liaison_taxe_modulaire");
Statement st3=c.createStatement();
ResultSet rs3=st3.executeQuery("select * from liaison_taxe_modulaire");
%>
 
 
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="Css/Css_choix_carte.css" rel="stylesheet">
         <link href="http://fr.allfont.net/allfont.css?fonts=crete-round" rel="stylesheet" type="text/css" />
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
         <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
         <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
         <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <title>JSP Page</title>
 
    </head>
    <body>
 
        <%
          String msg=(String) request.getAttribute("msg");
         
          
         if(msg!=null && !msg.equals("") ){
          %>  
          <script>
    $(document).ready(function(){
         $("#myModal").modal('toggle');
        
    });        
   
          
          </script>
 
          <% } %>
 
          <section>
        <div id="header_choix_carte">
            <h2>Choix de la carte</h2>
        </div>
        <form method="post" action="Choix_carte" enctype="multipart/form-data">
        <div id="div_num1">
 
            <div class="form-group form-inline">
 
                <label>Numéro de client :</label> 
                <input type="text" name="nclient" class="form-control form-control-md" id="nclient"/>
            </div>
 
        </div>
 
        <div id="div_num2">
 
            <div class="form-group form-inline">
 
                <label>Type de la carte :</label>  
 
                <select id="liste_a2" name="list1" class="form-control form-control-md">
                    <%while(rs.next()){%> 
                  <option><%=rs.getString(5) %></option>
                   <%}%>
                 </select>
 
            </div>
 
            <div class="form-group form-inline">
 
                 <label>Code tarif :</label> 
 
                 <select id="liste_2" name ="list2" class="form-control form-control-md">
                     <%while(rs1.next()){%> 
                  <option><%=rs1.getObject(4) %></option>
                   <%}%>
                 </select>
            </div>
 
        </div>
 
 
        <div id="div_num3">
 
            <div class="form-group form-inline">
                 <label>Gare de depart :</label> 
                 <input type="text" name="garedepart" class="form-control form-control-md" id="garedepart" value="00"/>
                 <select id="liste2" name="list3" class="form-control form-control-md">
                     <%while(rs2.next()){%> 
                  <option><%=rs2.getObject(2) %></option>
                   <%}%>
                 </select>
            </div>
 
            <div class="form-group form-inline">
 
                <label>Gare de destination :</label>  
                <input type="text" name="garedestination" class="form-control form-control-md" id="garedestination" value="00"/>
                <select id="liste3" name="list4" class="form-control form-control-md">
                     <%while(rs3.next()){%> 
                  <option><%=rs3.getObject(3) %></option>
                   <%}%>
                 </select>
            </div>
 
        </div>
 
 
        <div id="div_num4">
 
            <div class="form-group form-inline">
 
                <label>Début de validité :</label>  
                <input type="date" name="debutvalidite" class="form-control form-control-md" id="debutvalidite"/>
            </div>
 
            <div class="form-group form-inline">
 
                <label>Fin de validité :</label>  
                <input type="date" name="finvalidite" class="form-control form-control-md" id="finvalidite"/>
            </div>
        </div>
 
        <div id="button">
            <div class="form-group form-inline">
            <input type="submit" class="btn btn-warning btn-lg"  value="Confirmer">
            </div>
        </div>
 
        </form>
            </section>     
 
 
 
                 <div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
 
      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Information</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
 
      <!-- Modal body -->
      <div class="modal-body">
        ${msg}
      </div>
 
      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
 
    </div>
  </div>
</div>
 
 
 
 
 
    </body>
</html>




et voici le code de ma 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package Controllers;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 *
 * @author HP
 */
public class Choix_carte extends HttpServlet {
 
    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Choix_carte</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Choix_carte at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }
 
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        getServletContext().getRequestDispatcher("/WEB-INF/Choix_carte.jsp").forward(request, response);
    }
 
    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String list1=request.getParameter("list1");
        String list2=request.getParameter("list2");
        String list3=request.getParameter("list3");
        String list4=request.getParameter("list4");
        String nclient=request.getParameter("nclient");
        String debutvalidite=request.getParameter("debutvalidite");
        String finvalidite=request.getParameter("finvalidite");
        Connection c=cnx.getcnx();
        try{
            PreparedStatement st=c.prepareStatement("insert into liaison_taxe_modulaire values (null,?,?,?,?,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null)");
            st.setString(1, list1);
            st.setString(2, list2);
            st.setString(3, list3);
            st.setString(4, list4);
            int res1=st.executeUpdate();
            if(res1>0){
        request.setAttribute("msg","carte ajouter avec succés !");
    }
    else {
                   request.setAttribute("msg","erreur carte non ajouter");
         }
            PreparedStatement st1=c.prepareStatement("insert into clientpossedecartes values (null,null,null,?,?,null,null,null,null,null,?,null,null,null,null,null)");
            st1.setString(1, debutvalidite);
            st1.setString(2, finvalidite);
            st1.setString(3, nclient);
            int res=st1.executeUpdate();
            if(res>0){
        request.setAttribute("msg","carte ajouter avec succés !");
    }
    else {
                   request.setAttribute("msg","erreur carte non ajouter");
         }
        }
        catch(Exception ex){
           request.setAttribute("msg","Error");
            ex.printStackTrace();
        }
 
        getServletContext().getRequestDispatcher("/WEB-INF/Paiement.jsp").forward(request, response);
    }
 
    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
 
}


j'ai fais le meme code dans une autre page et ça marche voici le code que j'ai fais dans l'autre page qui fonctionne



page jsp :



Code jsp : 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<%@page import="java.util.Date"%>
<%@page import="Controllers.cnx"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <link href="Css/Css_ajout_recherche_client.css" rel="stylesheet">
         <link href="http://fr.allfont.net/allfont.css?fonts=crete-round" rel="stylesheet" type="text/css" />
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="js/Activationdesactivationbouton.js"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <title>JSP Page</title>
        <script>
            function chargerImg(){
                
                 documentgetElementBy Id("photo").src="UploadImg?cin="+documentgetElementById("Cin").value;          }
            
        </script>
    </head>
    <body>
        <%
          String msg=(String) request.getAttribute("msg");
         
          
         if(msg!=null && !msg.equals("") ){
          %>  
          <script>
    $(document).ready(function (){
         $("#myModal").modal('toggle');
        
    });        
   
          
          </script>
 
          <% }
         
          String Ncin="";
          String action=request.getParameter("action");
         
          String radio="";
String cin="";
String prenom="";
String prenomarabe="";
String nom="";
String nomarabe="";
String datenaissance="" ;
String tel="";
String email="";
String fonction="";
String organisme="";
String ministere="";
String adresse="";     
String nationalite="";
String ville="";
 
ResultSet r1=null;
 
        if("rechercher".equals(action)){
     
  Ncin=request.getParameter("Ncin");        
   
 
          
         ResultSet rs=  cnx.getcnx().createStatement().executeQuery("select * from clients where cin='"+Ncin+"'");
      if(rs.next()){
          
          prenom=rs.getString(4);
          prenomarabe=rs.getString(6);
          nom=rs.getString(3);
          nomarabe=rs.getString(5);
          Date dateN=rs.getDate(9);
          datenaissance=""+dateN;
          tel=rs.getString(8);
          email=rs.getString(10);
          fonction=rs.getString(19);
          organisme=rs.getString(11);
          ministere=rs.getString(12);
          adresse=rs.getString(7);
          radio=rs.getString(21);
          nationalite=rs.getString(17);
          ville=rs.getString(20);
          session.setAttribute("img", rs.getBytes(15));
         
          
              }
       }
        
        %>
 
        <section>
 
            <div id='header_ajout_recherche_client'>
                <h2>Ajout et recherche d'un client</h2>
            </div>
            <form method="POST"  class='form' enctype="multipart/form-data">
 
                <div id="div1">
 
                     <div class="form-group form-inline">
 
                    <label for="Ncin">Numero de la carte d'identité nationale :  </label>
                    <input type="text" name="Ncin" class="form-control form-control-md" id="Ncin" value="<%=Ncin %>"/>
                    <input type="submit" class="btn btn-warning btn-lg" name="action" value="rechercher" id="rechercher" onclick="chargerImg();" formaction="Ajout_recherche_client"> 
 
                    </div>
                </div>
 
 
 
                <div id="div_2">
                    <div class="form-group form-inline">
 
                    <label> Civilité : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </label>   
                    <label> Monsieur   &nbsp; &nbsp; &nbsp; </label>
                        <div class="form-check-input">
 
                            <input type="radio" class='form-check-input' value='1' <% if("1".equals(radio)){%> checked="" <%}%> name='radio' id="radio"/>
 
                        </div>
 
                    <label>&#1575;&#1604;&#1587;&#1610;&#1583; </label>
 
                    <label> &nbsp; &nbsp; &nbsp; Demoiselle &nbsp; &nbsp; &nbsp;</label>
 
                    <div class="form-check-input">
 
                                <input type="radio" class='form-check-input' value='2' <% if("2".equals(radio)){%> checked="" <%}%> name='radio' id="radio"/>
 
                        </div>
 
                    <label>&#1575;&#1604;&#1571;&#1606;&#1587;&#1577;</label>
 
                    <label> &nbsp; &nbsp; &nbsp; Madame  &nbsp; &nbsp; &nbsp; </label>
 
                     <div class="form-check-input">
 
                                <input type="radio" class='form-check-input' value='3'  <% if("3".equals(radio)){%> checked="" <%}%> name='radio' id="radio"/> &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp;
 
                        </div>
 
                    <label>&#1575;&#1604;&#1587;&#1610;&#1583;&#1577;</label>
                    </div>
                    <div class="form-group form-inline">
 
                        <label>Cin  &nbsp; &nbsp; &nbsp;</label>
                        <input type="text" name="cin" class="form-control form-control-md" id="Cin"  value="<%=Ncin %>"/> 
 
                        <label>  </label>
                    </div>
 
                    <div class="form-group form-inline">
 
                        <label>Prénom  &nbsp; &nbsp; &nbsp;</label>
                        <input type="text" name="prenom" class="form-control form-control-md" id="prenom" value="<%=prenom %>"/> 
                        <input type="text" name="prenomarabe" class="form-control form-control-md" id="prenomarabe"  value="<%=prenomarabe %>"/> 
                        <label> &#1575;&#1604;&#1571;&#1587;&#1605; &#1575;&#1604;&#1588;&#1582;&#1589;&#1610; </label>
                    </div>
 
                    <div class="form-group form-inline">
 
                        <label>Nom  &nbsp; &nbsp; &nbsp;</label>
                        <input type="text" name="nom" class="form-control form-control-md" id="nom" value="<%=nom %>"/> 
                        <input type="text" name="nomarabe" class="form-control form-control-md" id="nomarabe" value="<%=nomarabe %>"/> 
                        <label> &#1575;&#1604;&#1571;&#1587;&#1605; &#1575;&#1604;&#1593;&#1575;&#1574;&#1604;&#1610;</label>
                    </div>
 
 
 
                     <div class="form-group form-inline">
 
                        <label>Date de naissance   &nbsp; &nbsp; &nbsp;</label>
                        <input type="date" name="datenaissance" class="form-control form-control-md" id="datenaissance" value="<%=datenaissance %>"/> 
                        <label>Nationalité</label>
                        <select  name="nationalite" class="form-control form-control-md" id="nationalite" >
                        <%    r1=  cnx.getcnx().createStatement().executeQuery("select * from nationalites");
                               while(r1.next()){ %>
                               <option  <% if(r1.getString(1).equals(nationalite)){%> selected="" <%}%> value="<%=r1.getString(1)%>" ><%= r1.getString(2) %></option>
                               <% } %>
                        </select>  
                    </div>
 
                    <div class="form-group form-inline">
 
                        <label>Adresse   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;  </label>
                        <input type="text" name="adresse" class="form-control form-control-md" id="adresse" value="<%=adresse %>"/> 
 
                    </div>
 
                    <div class="form-group form-inline">
 
                        <label>Ville   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   </label>
                        <select  name="ville" class="form-control form-control-md" id="ville">
                         <%    r1=  cnx.getcnx().createStatement().executeQuery("select * from villes");
                               while(r1.next()){ %>
                               <option  <% if(r1.getString(1).equals(ville)){%> selected="" <%}%> value="<%=r1.getString(1)%>" ><%= r1.getString(2) %></option>
                               <% } %>
                        </select>
                        <label>Tel.personnel   &nbsp;   </label>
                        <input type="text" name="fixe" class="form-control form-control-md" id="fixe" value="+212" disabled="disabled"/> 
                        <input type="text" name="tel" class="form-control form-control-md" id="tel" value="<%=tel %>"/> 
                    </div>
 
 
                     <div class="form-group form-inline">
 
                        <label>Email   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp;  </label>
                        <input type="email" name="email" class="form-control form-control-md" id="email" value="<%=email %>"/> 
                        <label>Fonction   &nbsp;   </label>
                        <input type="text" name="fonction" class="form-control form-control-md" id="fonction" value="<%=fonction %>" /> 
 
                    </div>
 
                    <div class="form-group form-inline">
 
                        <label>Organisme   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   </label>
                        <input type="text" name="organisme" class="form-control form-control-md" id="organisme" value="<%=organisme %>"/> 
                        <label>Ministère  &nbsp;   </label>
                        <input type="text" name="ministere" class="form-control form-control-md" id="ministere" value="<%=ministere %>" /> 
 
                    </div>
                </div>
 
                <div id="div_3">
                    <div class="form">
                        <img  name="photo" src="UploadImg" class="form-control form-control-md" id="photo" width="200" height="200" /> 
 
                        <input type="file" name="fichier" class="btn btn-warning btn-lg" value="parcourir" /><br>
 
                </div>
                </div>
 
                <div id="div_4">
 
                     <div class="form-group form-group">
                         <a class="btn btn-warning btn-lg <%=(request.getAttribute("isEnabled")!= null) ? "" : "disabled" %>"  href="Choix_carte" id="carte" >Carte</a>
                         <input type="submit" class="btn btn-warning btn-lg"  name="action" value="enregistrer" id="enregistrer"  formaction="Ajout_recherche_client" >
                          <input type="submit" class="btn btn-warning btn-lg" name="action" value="modifier" formaction="Ajout_recherche_client">
                           <input type="reset" class="btn btn-warning btn-lg" value="Effacer">
                    </div>
 
 
                </div>
 
            </form>
        </section>
 
 
 
           <div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
 
      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Information</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
 
      <!-- Modal body -->
      <div class="modal-body">
        ${msg}
      </div>
 
      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>
 
    </div>
  </div>
</div>
 
 
 
 
    </body>
</html>




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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package Controllers;
 
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.resource.spi.ConfigProperty;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Client;
 
/**
 *
 * @author HP
 */
@MultipartConfig
public class Ajout_recherche_client extends HttpServlet {
 
    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
 
 
        }
    }
 
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/Ajout_recherche_client.jsp").forward(request, response);
    }
 
    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//ajout 
String radio=request.getParameter("radio");
String cin=request.getParameter("cin");
String prenom=request.getParameter("prenom");
String prenomarabe=request.getParameter("prenomarabe");
String nom=request.getParameter("nom");
String nomarabe=request.getParameter("nomarabe");
String datenaissance=request.getParameter("datenaissance") ;
String tel=request.getParameter("tel");
String email=request.getParameter("email");
String fonction=request.getParameter("fonction");
String organisme=request.getParameter("organisme");
String ministere=request.getParameter("ministere");
String adresse=request.getParameter("adresse");     
String nationalite=request.getParameter("nationalite"); 
String ville=request.getParameter("ville"); 
String action=request.getParameter("action");
 
InputStream img=null;
 
 
 
try{
    Connection c =cnx.getcnx();
    if("modifier".equals(action)){
 
        String req="update clients set NomFr=?, PrenomFr=?, NomAr=?, PrenomAr=?, Addresse=?, Telephone=?, DateNaissance=?, Email=?, Organisme=?, Ministere=?, Nationalite_Id=?, Fonction_Id=?, Ville_Id=?, CiviliteFr_Id=?  where cin='"+cin+"'";
 
 
        if(request.getPart("fichier") !=null) {
 
        req="update clients set NomFr=?, PrenomFr=?, NomAr=?, PrenomAr=?, Addresse=?, Telephone=?, DateNaissance=?, Email=?, Organisme=?, Ministere=?,  Nationalite_Id=?,  Fonction_Id=?, Ville_Id=?, CiviliteFr_Id=?, photo=?  where cin='"+cin+"'";
 
 
        } 
        PreparedStatement st=c.prepareStatement(req);
 
    st.setString(1, nom);
    st.setString(2, prenom);
    st.setString(3, nomarabe);
    st.setString(4, prenomarabe);
    st.setString(5, adresse);
    st.setString(6, tel);
    st.setDate(7, Date.valueOf(datenaissance));
 
    st.setString(8, email);
    st.setString(9, organisme);
    st.setString(10, ministere);
 
 
 
    st.setString(11, nationalite);
    st.setString(12, fonction);
    st.setString(13, ville);
    st.setInt(14,Integer.parseInt(radio));
 
     if(request.getPart("fichier") !=null) {
         System.out.println("ok");
          img=request.getPart("fichier").getInputStream();
 
          st.setBinaryStream(15,img);
 
    }
    int resM=st.executeUpdate();
        if(resM>0){
        request.setAttribute("msg","Client Modifier avec succés !");
    }
    else {
                   request.setAttribute("msg","Client n''est pas modifier");
         }
    }
    else if("enregistrer".equals(action)){
    PreparedStatement st=c.prepareStatement("insert into clients values (null,null,?,?,?,?,?,?,?,?,?,?,?,null,?,null,?,null,?,?,?)");
    st.setString(1, nom);
    st.setString(2, prenom);
    st.setString(3, nomarabe);
    st.setString(4, prenomarabe);
    st.setString(5, adresse);
    st.setString(6, tel);
    st.setDate(7, Date.valueOf(datenaissance));
 
    st.setString(8, email);
    st.setString(9, organisme);
    st.setString(10, ministere);
    st.setString(11, cin);
    img=request.getPart("fichier").getInputStream();
 
    st.setBinaryStream(12,img);
    st.setString(13, nationalite);
    st.setString(14, fonction);
    st.setString(15, ville);
    st.setInt(16,Integer.parseInt(radio));
    int res=st.executeUpdate();
 
    if(res>0){
        request.setAttribute("msg","Client Ajouté avec succés !");
    }
    else {
                   request.setAttribute("msg","Client n''est pas ajouté");
         }
    }
 
}
catch(Exception ex){
     request.setAttribute("msg","Error : Client n''est pas ajouté");
    ex.printStackTrace();
}finally{
    if(img !=null)
  img.close();
}
 
        request.setAttribute("isEnabled","true");
       getServletContext().getRequestDispatcher("/WEB-INF/Ajout_recherche_client.jsp").forward(request, response);
 
    }
 
    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
 
}


je sais pas pourquoi dans une elle marche et dans l'autre non certainement psk j'ai oublié un tout petit truc mais que je n'arrive pas à le détecter je vous suplis de répondre vite car j'ai la soutenance de mon projet bientot et il faut que je réalise mon rapport presentation ....



Merci d'avance !!!