merci l'importation fonctionne.. maintenant niveau utilisation ça ne parait pas évident pour un débutant dans la matiere comme moi ..
voici le formulaire html :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <form name="form1" method="post" action="reponse.jsp">
<table width="550" border="0" align="center" cellpadding="3" cellspacing="1" style="border: 1px solid #3399FF;">
<tr>
<td width="25%"><p> Catégorie :</p> </td>
<td width="75%"><select name="categorie">
<option value="0" selected>Choisissez une catégorie</option>
<option value="1" >Teacher</option>
<option value="2" >Student</option>
<option value="3" >Staff</option>
<option value="4" >Admin</option>
</select></td>
</tr>
<tr>
<td><p> Nom d'utilisateur :</p></td>
<td><input name="nomutilisateur" size="20" maxlength="40" type="text" value="">
<input type="submit" value="OK">
</td>
</tr> |
et la servlet :
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
| package argos;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.directory.*;
public class MoteurRecherche extends HttpServlet {
private String ListeNoms;
public String[] ChercherNom(String nom,String categorie)
{
String ListeNoms[] = null;
String Fournisseur = "com.sun.jndi.ldap.LdapCtxFactory" ;
String Hote = "ldap://172.16.1.1:389";
String base = "dc=personnes,dc=ac-bordeaux,dc=fr";
String rechbase;
Hashtable env = new Hashtable( ) ;
env.put(Context.INITIAL_CONTEXT_FACTORY, Fournisseur) ;
env.put(Context.PROVIDER_URL , Hote);
try {
DirContext ctx = new InitialDirContext(env) ;
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
rechbase = "eduPersonAffiliation="+ categorie +"," + base;
NamingEnumeration results = ctx.search(rechbase, "*"+nom+"*",constraints);
//Affichage des attributs
while (results != null && results.hasMore())
{
SearchResult entry = (SearchResult)results.next();
//Affichage du DN
Attributes attrs = entry.getAttributes();
if (attrs == null)
{
//afficher erreur première ligne du tableau
}
else {
//Affichage de chaque attribut
for (NamingEnumeration attEnum = attrs.getAll(); attEnum.hasMoreElements();)
{
Attribute attr = (Attribute)attEnum.next();
String attrId = attr.getID();
//Afficher les valeurs de l'attribut
Enumeration vals;
int i = 0;
//ICI IL FAUT METTRE DANS UN TABLEAU LES BONS ATTRIBUTS !
for (vals = attr.getAll();vals.hasMoreElements(); )
{
// out.println("<p><strong>"+ attrId + "</strong>: " + vals.nextElement() + "</p>");
if (attrId == "cn")
ListeNoms[i++] = (String) vals.nextElement();
}
}
}
}
}
catch (javax.naming.NamingException e){
e.printStackTrace();
}
return ListeNoms;
}
} |
cette servlet retourne une liste de noms qu'il faut récupérer en JSP donc j'essai par un fichier reponse.jsp
J'ai lu qu'il fallait utiliser les java beans pour cela
genre :
<jsp:useBean id="mybean" scope="session" class="argos.MoteurRecherche" />
ici il faut donc pouvoir utiliser la méthode "ChercherNom" pour que la liste nous soit retournée.
Une idée du comment faire?
Merci
Partager