EJB的编写方法
1定义一个业务方法接口
public interface HelloWorld {
public String SayHello(String name);
}
2编写BeanClass
@Stateless
@Remote ({HelloWorld.class})
public class HelloWorldBean implements HelloWorld {
3用eclipse打包想到或ant打成jar包
在jboss控制台可以看到部署成功
在jmx-console-》jboss-》service=JNDIView -》Operation-》list
可以看到Global JNDI Namespace
HelloWorldBean (class: org.jnp.interfaces.NamingContext)
4.编写客户端访问:
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
HelloWorld helloworld = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
out.println(helloworld.SayHello("佛山人"));
5.用ant或eclipse,把客户端文件打成war包,发布到jboss上
6.输入http://localhost:8080/EJBTest/Test.jsp访问
2
139
14KB
2010-12-02
13