Bonjour,
Je débute en J2EE et je teste l'appel d'EJB via une JSP.
Voici mon EJB :
Mon EJB de facade :
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
19package ejb; import javax.ejb.Stateless; import org.jboss.ejb3.annotation.Clustered; @Stateless //@Clustered public class CompteurEJB implements CompteurEJBRemote { @Override public int affiche(int msg) { //System.out.println(msg); return msg; } public int affiche2(int msg) { //System.out.println(msg); return msg * 2; } }
Ma JSP :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9package ejb; import javax.ejb.Remote; @Remote public interface CompteurEJBRemote { public int affiche(int msg); public int affiche2(int msg); }
Donc au début tout fonctionnait je n'avais en fait que la méthode affiche au niveau de l'EJB. Et celle ci n'affichait que sur la sortie standard :
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 <?xml version="1.0" encoding="UTF-8" ?> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import= "ejb.CompteurEJBRemote"%> <%@ page import= "javax.naming.*"%> <%@ page import= "java.text.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>JSP de stress</title> </head> <body> <table> <%! public void jspInit () { try { //System.out.println(CLASSE_OU_T_APPELLE_TON_JNDI.class.getClassLoader().getResource("jndi.properties").getPath()); InitialContext ctx = new InitialContext(); int num; CompteurEJBRemote s = (CompteurEJBRemote) ctx.lookup("CompteurEJB/remote"); for (int i = 0; i < 300; i++) { %><tr><td><%! num=s.affiche(i); // Thread.sleep(1000); %><%= out.println(num) %> </td></tr><%! } } catch (Exception e) { e.printStackTrace (); } } %> </table> </body> </html>
Ensuite j'ai souhaité la modifiée (c'est donc le code un peu plus haut) pour que celle ci retourne un entier afin de le récupérer au niveau de ma JSP pour ensuite l'afficher.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4public void affiche(int msg) { System.out.println(msg); }
Mais j'ai un message d'erreur : cannot convert from void to int
En effet sous éclipse l'auto completion de ma JSP me propose la méthode affiche qui retourne void et non int, de même la méthode affiche2 rajoutée par la suite n'est pas visible.
J'ai du oublier un morceaux qq part. Si qqn à une idée.
De plus voici mon web.xml :
Merci par avance
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 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>clientcompteurweb</display-name> <servlet> <description>Point d'entree de l'application</description> <display-name>Controlpea</display-name> <servlet-name>Controlpea</servlet-name> <servlet-class>com.saintquentin.pea.Controlpea</servlet-class> </servlet> <servlet-mapping> <servlet-name>Controlpea</servlet-name> <url-pattern>/Controlpea</url-pattern> </servlet-mapping> <resource-env-ref> <description>Bind de mon bean</description> <resource-env-ref-name>CompteurEJB/remote</resource-env-ref-name> <resource-env-ref-type>ejb.CompteurEJB</resource-env-ref-type> <mapped-name>java:CompteurEJB/remote</mapped-name> </resource-env-ref> </web-app>
couse1








Répondre avec citation
Partager