Tworzenie aplikacji Enterprise - poprawny kod, w instrukcji jest inny! 5 XII 2009.
Krok 5 f)
package eapp;
import ejb.MathRemote;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
*
* @author superstudent
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws NamingException {
// TODO code application logic here
InitialContext ctx = new InitialContext();
MathRemote mathBean = (MathRemote)ctx.lookup("MB");
System.out.println(mathBean.getHello());
System.out.println(" 5x6 = " + mathBean.multiply(5, 6));
}
}
Krok 6 a)
package ejb;
import javax.ejb.Stateless;
/**
*
* @author superstudent
*/
@Stateless(mappedName="MB")
public class MathBean implements MathRemote {
int temp=0;
public String getHello() {
return "Hello Student!";
}
public int multiply(int a, int b) {
temp = temp + a*b;
return temp;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}