[JSP]utilisation d'un Bean
Salut,
je voudrais utiliser une bean dans ma jsp qui permet d'avoir des infos sur un utilisateur.
Code:
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
| <body>
<jsp:useBean id="client" scope="session" class="divers.Client" />
<div id="entete">
<div id="haut">
<img src="img/coinexg_ent.gif" id="coinexg_ent"/>
<img src="img/coinb_logo.gif" id="coinb_logo"/>
<div id="logo">
<img src="img/logo.gif" width="150" height="70"/>
</div>
<div id="navbar">
<img src="img/coing_ent.gif" id="coing_ent"/>
<img src="img/coind_ent.gif" name="coind_ent" id="coind_ent"/>
<a href="index.jsp">accueil</a>
<%
client.execRequete("walid");
if (request.getRemoteUser()!=null)
{
out.print("| <a href='decon.jsp'>déconnexion </a>");
}
%>
| <a href="index.jsp">plan du site</a>
<div id="perm">
<%
if (request.getRemoteUser()!=null)
{
out.print(client.getNom() + "<br>");
out.print("<a href='compte.jsp'>Mon compte</a>");
}
else
{
out.print("<a href=\"enregistrement.jsp\">Inscription</a>");
}
%>
<a href="aide.jsp">Aide</a>
</div>
<div id="recherche">
<form name="recherche" method="GET" action="recherche.jsp">
<input name="recherche" type="text"/> <input name="submit" type="submit" value="rechercher"/>
</form>
</div>
</div>
</div>
</div>
<div id="tout">
<img src="img/arrondig.gif" id="coing"/>
<div id="menu">
<%@ include file="menu.jsp" %>
</div>
<img src="img/arrondid.gif" id="coind"/>
<div id="contenu">
<%@ include file="index_inc.jsp" %>
</div>
</div>
</body> |
voici ma page de test, elle devrait utilser les méthodes de la classe suivante :
Code:
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
| package divers;
import java.sql.*;
public class Client
{
public Client()
{
}
private String login, mdp, nom, prenom, email, adresse, ville, cp, telephone, sexe, naissance, role, admin;
private boolean virtuel;
private Connection con;
private Statement st;
private ResultSet lers ;
public void execRequete(String lelogin) throws Exception
{
Connection con = Connexion.getConnection();
Statement st=con.createStatement();
ResultSet rs = st.executeQuery("select * from clients where login='"+ lelogin +"';");
this.nom = rs.getString("nom");
this.prenom = rs.getString("prenom");
this.email = rs.getString("email");
this.adresse = rs.getString("adresse");
this.ville = rs.getString("ville");
this.cp = rs.getString("cp");
this.telephone = rs.getString("telephone");
this.sexe = rs.getString("sexe");
this.naissance = rs.getString("naissance");
this.role = rs.getString("role");
con.close() ;
}
public boolean estAdmin()
{
return (admin.equals("admin"));
}
public String getNom()
{
return nom;
} |
Par contre ca ne marche pas, je seche dessus depuis super longtemps, j'ai tout essayé et je ne sais pas ce qui marche pas.
Quelqu'un pourrait m'aider?