Bonjour,
Voici mon problème : lorsque je teste mon web service j'obtiens ceci :
J'ai donc l'assurance que celui-ci fonctionne correctement (en fait mon web service récupère sous la forme d'une liste de string les attributs d'un livre dont le numéro isbn est passé en paramètre).
En revanche lorsque j'essaie d'afficher ce résultat sous la forme d'un tableau à l'aide du code suivant (dans books.jsp) :
J'obtiens ceci.
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 try { pack.WebServiceBook_Service service = new pack.WebServiceBook_Service(); pack.WebServiceBook port = service.getWebServiceBookPort(); // TODO initialize WS operation arguments here java.lang.String isbn = ""; // TODO process result here java.util.List<java.lang.String> result = port.searchBook(isbn); %> <br><br> <table width="300px" border="1"> <tr><td>Id</td><td>title</td><td>Isbn</td><td>author</td><td>abstract</td></tr> <% for(int i=0; i < result.size(); i++) { String[] c = result.get(i).toString().split(" / "); out.println("<tr><td>"+c[0]+"</td><td>"+c[1]+"</td><td>"+c[2]+"</td><td>"+c[3]+"</td><td>"+c[4]+"</td></tr>"); } %> </table> <% } catch (Exception ex) { throw new RuntimeException(ex); } %>
Je rajoute le code du web service qui peut servir si jamais l'erreur vient de result.get(i).toString().split(" / ");
Merci beaucoup à tous ceux qui essaieront de m'aider.
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 @WebMethod(operationName = "SearchBook") public List book(@WebParam(name = "isbn") String isbn) { try{ List book = new ArrayList(0); try { connect(); statement = conn.createStatement(); res = statement.executeQuery("select * from book where isbn ='"+isbn+"'"); while(res.next()) book.add(res.getString(1)+" / "+res.getString(2)+" / "+res.getString(3)+" / "+res.getString(4)+" / "+res.getString(5)); statement.close(); res.close(); } catch(SQLException ex) { Logger.getLogger(WebServiceBook.class.getName()).log(Level.SEVERE, null, ex); } return book; }catch(Exception e){ throw new RuntimeException(e); } }
Partager