Salut tout le monde voici ma situation :
J'ai réalisé un moteur de recherche à partir d'une base de données, mon problème c'est que la boucle que j'ai développé dans la page JSP retourne juste le premier résultat correspondant à la valeur recherchée(la valeur recherchée est une designation d'un produit ) alors que je souhaite avoir la liste de tout les valeur correspondante dans ma BD .
voici ma page JSP :
<h3 align="center">Resultat recherche</h3>
<jsp:useBean id="utilisateur" class="bd.Produit">
<jsp:setProperty name="utilisateur" property="*" />
<tr>
<td bgcolor="#FF9900" width="100"><b>Designation recherchée : </b></td>
<td><jsp:getProperty name="utilisateur" property="designation" /></td>
</tr>
</table></p>
<tr bgcolor="#FF6600">
<th>Code</th>
<th>Designation</th>
</tr>
<%
int ligne = 0;
while (utilisateur.suivant()) {
if (utilisateur.enregistrer()) {
%>
<font color="red">
<tr bgcolor="<%= ligne++ % 2 == 0 ? "#FFFF66" : "#FFCC00" %>">
<td><b><%= utilisateur.code() %></b></td>
<td><%= utilisateur.designation() %></td>
</tr></font> </font>
<%
} else {
%>
<font color="red">Produit inexistant !</font>
<%
}
utilisateur.arrêt(); }
%>
</h3>
</table>
</jsp:useBean>
<%@ include file = "/WEB-INF/classes/jspf/pieds.jsp" %>
voici mon javaBean
package bd;
import java.sql.SQLException;
public class Produit extends ConnexionBD {
private int code;
private String designation ;
public Produit() {
lire("SELECT * FROM produit WHERE designation=\""+designation+"\"");
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public boolean enregistrer() {
if (existeDéjà())
return true;
else return false;
}
public boolean existeDéjà() {
lire("SELECT * FROM Produit WHERE designation=\""+designation+"\" ");
return suivant();
}
public String identificateur(){
lire("SELECT code FROM produit WHERE code=\""+code+"\" AND designation=\""+designation+"\"");
suivant();
try {
return résultat.getString("code");
}
catch (SQLException ex) {
return null ;
}
}
public String code() {
try {
return résultat.getString("code");
} catch (SQLException ex) {
return "";
}
}
public String designation() {
try {
return résultat.getString("designation");
} catch (SQLException ex) {
return "";
}
}
}
Partager