Bonjour à tous !
Bon voilà, je travaille sur un projet java web application en ce moment et j'ai un problème qui n'est pas très fréquent je pense car je ne trouve pas de solution sur le net depuis maintenant une semaine. Voilà ce qui se passe, j'utilise Mysql comme SGBD , et lors d'une tentative de login c'est à dire (LoginPage.jsp==>LoginServlet), tout fonctionne correctement, après vérification des champs, des données dans la base de données sont récupérés et puis sont mises dans la variable request puis j'emplois un RequestDispatcher pour rediriger vers la vue correspondant en fonction de "un user ou l'admin" :
.
Code Java : 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 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controllerPackage; import daoPackage.LoginDao; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Vector; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import modelPackage.Sakafo; import modelPackage.User; /** * * @author */ public class LoginServlet extends HttpServlet { String name2; /** * 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 */ // <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 */ /** * 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{ response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); LoginDao lgDao = new LoginDao(); String username = request.getParameter("username"); String mdp = request.getParameter("motsDePasse"); HttpSession sess; try{ Vector verite = lgDao.validationLogin(username,mdp); if((int)verite.get(0)==1) //VERIFICATION LOGIN { if("admin".equals((String)verite.get(1))){ //RAHA ADMIN sess=request.getSession(); sess.setAttribute("inona", "admin"); /*User user = new User(); //RECUPERATION TOUT USER User[] listeUser = user.getAllUser(); List userVrai = new ArrayList(); for(int j=0; j<listeUser.length; j++) { userVrai.add(listeUser[j]); } request.setAttribute("listeAllUser",userVrai);*///INSERTION USER DANS REQUEST Sakafo sakafo = new Sakafo(); //RECUPERATION TOUT SAKAFO Sakafo[] listeSakafo = sakafo.getAllSakafo(); /*List listeSakafoVrai=new ArrayList(); listeSakafoVrai.addAll(Arrays.asList(listeSakafo));*/ //INSERTION DANS LIST DU TABLEAUX ALL SAKAFO request.setAttribute("listeSakafo",listeSakafo);//INSERTION SAKAFO DANS REQUEST RequestDispatcher rd = request.getRequestDispatcher("acceuilAdmin.jsp"); rd.include(request,response);//FIN RAHA ADMIN } else if("user".equals((String)verite.get(1))){ //RAHA USER sess = request.getSession(); sess.setAttribute("inona","user"); sess.setAttribute("idUser",(int)verite.get(2)); Sakafo sakafo = new Sakafo(); //RECUPERATION TOUT SAKAFO Sakafo[] listeSakafo = sakafo.getAllSakafo(); request.setAttribute("listeSakafo",listeSakafo);//INSERTION DANS REQUEST RequestDispatcher rd = request.getRequestDispatcher("acceuilUser.jsp"); rd.include(request,response);//FIN RAHA USER } } else{ //SI ERROR out.print("Username ou mot de passe incorrecte!"); RequestDispatcher rd = request.getRequestDispatcher("LoginPage.jsp"); rd.include(request,response); } } catch(Exception e) { System.out.println(e); } } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }
Tous ça se déroule très bien, mais arrivé dans l'accueil user , j'entre dans le coin recherche qui est un lien .jsp , c'est dans la "view" "coinRecherche.jsp" que mon problème se passe, au niveau du formulaire de recherche , quand j'appuis sur le bouton rechercher ,aucune réaction, rien ne se passe.
accueilUser.jsp:
coinRecherche.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
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 <%@page import="modelPackage.Sakafo"%> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <link rel="shortcut icon" href="assets/img/ico/favicon.ico"> <link rel="apple-touch-icon" sizes="144x144" href="assets/img/ico/apple-touch-icon-144x144.png"> <link rel="apple-touch-icon" sizes="114x114" href="assets/img/ico/apple-touch-icon-114x114.png"> <link rel="apple-touch-icon" sizes="72x72" href="assets/img/ico/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" href="assets/img/ico/apple-touch-icon-57x57.png"> <title>Tino's Ristorante</title> <!-- Bootstrap Core CSS --> <link href="assets/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/animate.css" rel="stylesheet"> <link href="assets/css/plugins.css" rel="stylesheet"> <!-- Custom CSS --> <link href="assets/css/style.css" rel="stylesheet"> <!-- Custom Fonts --> <link href="assets/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="assets/css/pe-icons.css" rel="stylesheet"> </head> <body id="page-top" class="regular-navigation"> <div class="master-wrapper"> <div class="preloader"> <div class="preloader-img"> <span class="loading-animation animate-flicker"><img src="assets/img/loading.GIF" alt="loading" /></span> </div> </div> <!-- Navigation --> <nav class="navbar navbar-default navbar-fixed-top fadeInDown" data-wow-delay="0.2s"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header page-scroll"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand smoothie" href="index.html">Tino's<span class="theme-accent-color"> Ristorante</span></a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="main-navigation"> <ul class="nav navbar-nav navbar-right"> <li><a href="DeconnexionServlet" class="page-scroll">Deconnexion</a></li> <li><a href="#about" class="page-scroll">Menu</a></li> <li><a href="coinReherche.jsp" class="page-scroll">Coin Recherche</a></li> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> </nav> <!-- Header --> <header id="headerwrap" class="backstretched fullheight"> <div class="container-fluid fullheight"> <div class="vertical-center row"> <div class="col-sm-1 pull-left text-center slider-control match-height"> <a href="#" class="prev-bs-slide vertical-center wow fadeInLeft" data-wow-delay="0.8s"><i class="fa fa-long-arrow-left"></i></a> </div> <div class="intro-text text-center smoothie col-sm-10 match-height"> <div class="intro-heading wow fadeIn heading-font" data-wow-delay="0.8s"><img src="assets/img/intro-logo.png"></div> </div> <div class="col-sm-1 pull-right text-center slider-control match-height"> <a href="#" class="next-bs-slide vertical-center wow fadeInRight" data-wow-delay="0.8s"><i class="fa fa-long-arrow-right"></i></a> </div> </div> </div> </header> <section id="about" class="top-border-me"> <div class="container"> <div class="row"> <!--RECUPERATION LISTE SAKAFO --> <% Sakafo[] listeSakafo = (Sakafo[]) request.getAttribute("listeSakafo"); %> <% for(int i=0; i<listeSakafo.length;i++){ %> <div class="col-md-6"> <div class="pd-card" style="width: 18rem; margin-top:10px;"> <img src="images/<%= listeSakafo[i].getUrlImage() %>" width="100" height="70" class="card-img-top" alt="Card image cap"> <div class="card-body"> <h5 class="card-title"><%= listeSakafo[i].getNomSakafo() %></h5> <a href="DescriptionServlet?idSakafo=<%= listeSakafo[i].getIdSakafo() %>" class="btn btn-primary">View details</a> </div> </div> </div> <% } %> </div> </div> <div class="pd-filter-pagination" data-pagination="3"></div> </section> <footer class="white-wrapper"> <div class="container-fluid"> <div class="row text-center"> <div class="col-md-12 wow fadeIn mb30" data-wow-delay="0.2s"> <span class="copyright">Copyright 2021.</span> </div> <div class="col-md-12"> <ul class="list-inline social-links wow fadeIn" data-wow-delay="0.2s"> <li> <a href="#"><i class="fa fa-twitter"></i></a> </li> <li> <a href="#"><i class="fa fa-pinterest"></i></a> </li> <li> <a href="#"><i class="fa fa-dribbble"></i></a> </li> <li> <a href="#"><i class="fa fa-facebook"></i></a> </li> <li> <a href="#"><i class="fa fa-behance"></i></a> </li> <li> <a href="#"><i class="fa fa-linkedin"></i></a> </li> </ul> </div> </div> </div> </footer> <div id="bottom-frame"></div> <a href="#" id="back-to-top"><i class="fa fa-long-arrow-up"></i></a> </div> <script src="assets/js/jquery.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/plugins.js"></script> <script src="assets/js/init.js"></script> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <script type="text/javascript"> $(document).ready(function(){ 'use strict'; jQuery('#headerwrap').backstretch([ "assets/img/bg/bg1.jpg", "assets/img/bg/bg2.jpg", "assets/img/bg/bg3.jpg", ], {duration: 8000, fade: 500}); }); </script> </body> </html>
La servlet de traitement de la recherche:
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 <%@page import="modelPackage.Sakafo"%> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <link rel="shortcut icon" href="assets/img/ico/favicon.ico"> <link rel="apple-touch-icon" sizes="144x144" href="assets/img/ico/apple-touch-icon-144x144.png"> <link rel="apple-touch-icon" sizes="114x114" href="assets/img/ico/apple-touch-icon-114x114.png"> <link rel="apple-touch-icon" sizes="72x72" href="assets/img/ico/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" href="assets/img/ico/apple-touch-icon-57x57.png"> <title>Coin Rechercher</title> <!-- Bootstrap Core CSS --> <link href="assets/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/animate.css" rel="stylesheet"> <link href="assets/css/plugins.css" rel="stylesheet"> <link href="css/bootstrap-4.3-2.1-dist/css/bootstrap.css" rel="stylesheet"> <!-- Custom CSS --> <link href="assets/css/style.css" rel="stylesheet"> <!-- Custom Fonts --> <link href="assets/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="assets/css/pe-icons.css" rel="stylesheet"> </head> <body id="page-top" class="regular-navigation"> <div class="master-wrapper"> <div class="preloader"> <div class="preloader-img"> <span class="loading-animation animate-flicker"><img src="assets/img/loading.GIF" alt="loading" /></span> </div> </div> <!-- Navigation --> <nav class="navbar navbar-default navbar-fixed-top fadeInDown" data-wow-delay="0.2s"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header page-scroll"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand smoothie" href="index.html">Coin<span class="theme-accent-color"> Recherche</span></a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="main-navigation"> <ul class="nav navbar-nav navbar-right"> <li><a href="DeconnexionServlet" >Deconnexion</a></li> <li><a href="acceuilServlet" >Acceuil</a></li> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> </nav> <header id="headerwrap" class="backstretched fullheight"> <div class="container-fluid fullheight"> <div class="vertical-center row"> <div class="col-sm-1 pull-left text-center slider-control match-height"> <a href="#" class="prev-bs-slide vertical-center wow fadeInLeft" data-wow-delay="0.8s"><i class="fa fa-long-arrow-left"></i></a> </div> <div class="intro-text text-center smoothie col-sm-10 match-height"> <div class="intro-heading wow fadeIn heading-font" data-wow-delay="0.8s"><img src="assets/img/intro-logo.png"></div> </div> <div class="col-sm-1 pull-right text-center slider-control match-height"> <a href="#" class="next-bs-slide vertical-center wow fadeInRight" data-wow-delay="0.8s"><i class="fa fa-long-arrow-right"></i></a> </div> </div> </div> </header> <section id="about" class="top-border-me"> <div class="container"> <div class="row" style="margin-top:10px;margin-bottom: 10px"> <!-- DIV RESULTAT RECHERCHE --> <div class="col-sm-8"> </div> <!-- COIN BARRE DE RECHERCHE AVEC D'AUTRE PARAMETRE --> <form action="TraitementSearch" method="post"> <div class="col-sm-4"> <!-- DESIGNATION --> <label for="floatdesignation">Designation</label> <input type="text" id="floatdesignation" style="width:200px; height:30px" class="form-control" name="designation" aria-describedby="inputGroup-sizing-lg"> <!-- FIN DESIGNATION --> <!-- DEBUT CATEGORIE --> <h4><u>Categorie:</u></h4> <select class="form-select" name="categorie"> <option value="0" selected>All</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> <!-- FIN CATEGORIE --> <!-- DEBUT DIFFICULTE --> <h4><u>Difficulte:</u></h4> <select class="form-select" name="difficulte"> <option value="1" selected>1</option> <% for(int diff=2; diff<=10; diff++){ %> <option value="<%= diff %>"><%= diff %></option> <% } %> </select> <!-- FIN DIFFICULTE --> <!-- DEBUT PRIX MIN --> <h4><u>Prix min:</u></h4> <select class="form-select" name="prixMin"> <option value="10" selected>10</option> <% for(int prixMin=11; prixMin<=200; prixMin++){ %> <option value="<%= prixMin %>"><%= prixMin %></option> <% } %> </select> <!-- FIN PRIX MIN --> <!-- DEBUT PRIX MAX --> <h4><u>Prix max:</u></h4> <select class="form-select" name="prixMax"> <option value="200" selected>200</option> <% for(int prixMax=199; prixMax>=10; prixMax--){ %> <option value="<%= prixMax %>"><%= prixMax %></option> <% } %> </select></br> <!-- FIN PRIX MAX --> <input type="submit" class="btn btn-outline-success" value="Rechercher"> </div> </form> </div> </div> <div class="pd-filter-pagination" data-pagination="3"></div> </section> <footer class="white-wrapper"> <div class="container-fluid"> <div class="row text-center"> <div class="col-md-12 wow fadeIn mb30" data-wow-delay="0.2s"> <span class="copyright">Copyright 2021.</span> </div> <div class="col-md-12"> <ul class="list-inline social-links wow fadeIn" data-wow-delay="0.2s"> <li> <a href="#"><i class="fa fa-twitter"></i></a> </li> <li> <a href="#"><i class="fa fa-pinterest"></i></a> </li> <li> <a href="#"><i class="fa fa-dribbble"></i></a> </li> <li> <a href="#"><i class="fa fa-facebook"></i></a> </li> <li> <a href="#"><i class="fa fa-behance"></i></a> </li> <li> <a href="#"><i class="fa fa-linkedin"></i></a> </li> </ul> </div> </div> </div> </footer> <div id="bottom-frame"></div> <a href="#" id="back-to-top"><i class="fa fa-long-arrow-up"></i></a> </div> <script src="assets/js/jquery.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/plugins.js"></script> <script src="assets/js/init.js"></script> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <script type="text/javascript"> $(document).ready(function(){ 'use strict'; jQuery('#headerwrap').backstretch([ "assets/img/bg/bg1.jpg", "assets/img/bg/bg2.jpg", "assets/img/bg/bg3.jpg" ], {duration: 8000, fade: 500}); }); </script> </body> </html>
J'éspère sincèrement trouver de l'aide car ça fait des jours que je tourne autour et je commence vraiment à perdre éspoir, merci.
Code Java : 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 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controllerPackage; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author P13A-101-Tino */ public class TraitementSearch 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. */ } } // <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 { processRequest(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 designation = request.getParameter("designation"); String categorie = request.getParameter("categorie"); String difficulte = request.getParameter("difficulte"); String prixMin = request.getParameter("prixMin"); String prixMax = request.getParameter("prixMax"); RequestDispatcher rd = getServletContext().getRequestDispatcher("ResultatRecherche.jsp"); rd.include(request,response); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }
Partager