是一个有状态会话bean
下列是接口
package com.abc;
public interface Ihello {
public int add(int a,int b);
public int getTotal();
}
实现类
package com.abc.impl;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateful;
import com.abc.Ihello;
@Stateful
@Remote ({Ihello.class})
@Local ({Ihello.class})
public class Hello implements Ihello {
private int total=0;
private int addresult=0;
public int add(int a, int b) {
total=a+b;
return total;
}
public int getTotal() {
addresult+=total;
return addresult;
}
}
导入的包是server/all/lib下的所有包
<%@ page contentType="text/html; charset=gbk" %>
<%@ page import="com.abc.Ihello,javax.naming.*,java.util.Properties" %>
<%
Properties prop=new Properties();
prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.provider.url","localhost:1099");
prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming");
try{
InitialContext ctx=new InitialContext(prop);
out.println("--------------");
Ihello hello=(Ihello)ctx.lookup("Hello/local");
out.println("add:"+hello.add(2,6));
out.println("getTotal:"+hello.getTotal());
}catch(Exception e){
out.println(e.getMessage());
}
%>
web.xml中内容
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>EBJ3.0 Test</description>
</web-app>
运行总是出现null,不知道是怎么回事,问老师,老师让我们用低版本的tomacat5.5,我用的是6.0,搞的烦死了,斑上80%的人,都出现这样的问题,老师真的很水,请教高人指点迷津!!!!