Salut à tous
j'ai un soucis et j'ai pas trouvé de solution avec la fonction recherche
Dans mon appli struts, j'appelle un service web qui effectue une requete et me renvoi un arrayList.
Le hic c'est que j'ai cet erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part error >> java.lang.ClassCastException: [Ljava.lang.Object;
L'APPEL DU SERVICE WEB
LE SERVICE WEB
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 //////////////////////////////////////////////////////// /* * GESTION DU CADDIE (AFFICHAGE) */ public static ArrayList ShowCart(String UserName, String Password, String base) { try { //STEP 1/7 //création de l'acces vers le service Service service = new Service(); //STEP 2/7 //creation d'un appel vers le service Call appel = (Call) service.createCall(); //STEP 3/7 //recuperation de l'adresse URL du service a consommer //String endpoint = "http://localhost:8080/axis/services/UnServiceAxis"; appel.setTargetEndpointAddress(new java.net.URL(endpoint)); //STEP 4/7 //gestion du parametres appel.setOperationName( new QName( "ns", "getQuote" ) ); //step 5/7 on met le/les parametre(s) appel.addParameter( "UserName", XMLType.XSD_STRING, ParameterMode.IN ); appel.addParameter( "Password", XMLType.XSD_STRING, ParameterMode.IN ); appel.addParameter( "base", XMLType.XSD_STRING, ParameterMode.IN ); //step 6/7 //IMportant et partique : donner le type de retour (float datetime etc ...) appel.setReturnType( XMLType.SOAP_ARRAY);// .XSD_STRING);// .XSD_FLOAT ); //STEP 7/7 //caddie Object = new Object[100]; tableau = (ArrayList)appel.invoke("AGetInfoCart",new Object[]{UserName,Password,base}); // String nom = ((Hashtable)tableau.get(0)).get("Id_Souche").toString(); // String nom1 = ((Hashtable)tableau.get(1)).get("Id_Souche").toString(); // String nom2 = ((Hashtable)tableau.get(2)).get("Id_Souche").toString(); // System.out.println("Réponse SW >> "+nom+nom1+nom2); } catch (Exception e2) { //String tableau_error = e2.toString(); System.err.println("error >> "+e2.toString()); } return tableau; }
Evidemment quand je place la méthode du service web dans l'Action Bean, celle ci fonctionne parfaitement. Comment faire pour retourner un ArrayList par le service web? merci d'avance pour votre aide
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 public static ArrayList AGetInfoCart (String UserName, String Password, String bdd) { // //USAGE GENERAL = AFFICHAGE DES DONNEES DU CADDIE // String URL = "jdbc:mysql://localhost/"+bdd+""; Connection connect; ArrayList tableau = new ArrayList(); try { //Chargement du pilote Class.forName("com.mysql.jdbc.Driver").newInstance(); //etablissement de la connexion avec authentification connect = DriverManager.getConnection(URL,user,password); //creation d'un etat pour faire la requete Statement smt = connect.createStatement(); //ResultSet Resultat; ResultSet Resultat = null; //Obtient l'Id du client par son login String requete1 = "SELECT Client_Id from client where Login_Client='"+UserName+"';"; Resultat = smt.executeQuery(requete1); Resultat.first(); int Ident_Client = Resultat.getInt(1); //Obtient les commandes actuellement en cours pour l'utilisateur String requete = "Select NomSouche, quantite, DateCommande, Commande_Id from souche, commande " + "where commande.Ident_Souche=souche.Souche_Id and Ident_Client="+Ident_Client+" " + "AND commande.Fait='N';"; Resultat = smt.executeQuery(requete); int i =0; String Id_Souche, DateCaddie, Quantite, Commande_Id; while (Resultat.next()) { Hashtable list = new Hashtable(); Id_Souche = Resultat.getString(1); list.put("Id_Souche",Id_Souche); Quantite = Resultat.getString(2); list.put("quantite",Quantite); DateCaddie = Resultat.getString(3); list.put("date",DateCaddie); Commande_Id = Resultat.getString(4); list.put("id",Commande_Id); tableau.add(i,list); //System.out.println(Id_Souche+" "+Quantite+" "+DateCaddie+" "+Commande_Id+" "+i); i++; } // String nom = ((Hashtable)tableau.get(0)).get("Id_Souche").toString(); // String nom1 = ((Hashtable)tableau.get(1)).get("Id_Souche").toString(); // String nom2 = ((Hashtable)tableau.get(2)).get("Id_Souche").toString(); // System.out.println("nom du tableau "+nom+nom1+nom2); //fermeture de la connexion connect.close(); } catch (Exception e2) { System.out.println("erreur >> "+e2.toString()); } return tableau; }![]()
Partager