Bonjour,
J'ai crée une fonction recherche qui récupère des informations dans un fichier xml et les affiches , je voudrais les afficher sur une page web via un fichier jsp
mais quand je crée ma fonction dans le jsp avec <%! %> il ne reconnait pas out.println. Je voudrais savoir comment faire en sorte que ma fonction affiches les donnée sur la page web. (j'ai aussi une servlet qui récupère les données qui permettront de faire la recherche et les envoies à la fonction 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 package packageTreatment; import java.io.*; import org.jdom2.*; import org.jdom2.input.*; import java.util.List; import java.util.Iterator; import java.util.StringTokenizer; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; public class Rechercher { static org.jdom2.Document document; static Element racine; static String name; /* public static void main(String[] args) { //String nom = "Menethil"; //String prenom = "Arthas"; SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("WebContent/annuaire.xml")); } catch(Exception e){} affiche(nom,prenom); } */ public static void cherche(String parNom, String parPrenom, HttpServletResponse response) throws ServletException, IOException { SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(new File("WebContent/annuaire.xml")); } catch(Exception e){} racine = document.getRootElement(); List<Element> personne = racine.getChildren("personne"); Iterator<Element> i = personne.iterator(); while(i.hasNext()) { Element courant = (Element)i.next(); String id = courant.getAttributeValue("id"); if(teste(parNom,parPrenom,id)) { System.out.println(courant.getChild("prenom").getText()); System.out.println(courant.getChild("nom").getText()); System.out.println(courant.getChild("adresse").getText()); System.out.println(courant.getChild("email").getText()); System.out.println(courant.getChild("numFixe").getText()); System.out.println(courant.getChild("numPortable").getText()); System.out.println(courant.getChild("commentaire").getText()); } } } static boolean teste (String nom, String prenom, String id) { String[] nomPrenom = new String[2]; int i=0; boolean bool = false ; StringTokenizer st = new StringTokenizer(id,"||"); while (st.hasMoreTokens()) { nomPrenom[i] = st.nextToken(); i++; } if ( (nomPrenom[0].equals(prenom)) || (nomPrenom[1].equals(nom)) ) { bool = true ; } return bool; }
Partager