haihome.java:
package ejbs;
import java.io.serializable;
import java.rmi.*;
import javax.ejb.*;
public interface haihome extends ejbhome {
haiclient create() throws remoteexception, createexception;
}
package ejbs;
import javax.ejb.*;
import java.rmi.remoteexception;
public interface haiclient extends ejbobject {
public string sayhai() throws remoteexception;
}
haibean.java:
package ejbs;
import javax.ejb.*;
import javax.naming.*;
public class haibean implements sessionbean {
public string sayhai() {
return "hai, ejb technology!";
}
public void ejbcreate() throws ejbexception {}
public void ejbremove() throws ejbexception {}
public void ejbpassivate() {}
public void ejbactivate() {}
public void setsessioncontext(sessioncontext sc) {}
}
<?xml version="1.0" encoding="utf-8"?>
<!doctype ejb-jar public ’-//sun microsystems, inc.//dtd enterprise javabeans 2.0//en’ ’http://java.sun.com/dtd/ejb-jar_2_0.dtd’>
<ejb-jar>
<description>hai ejb instance.</description>
<display-name>hai ejb</display-name>
<enterprise-beans>
<session>
<ejb-name>haiejb</ejb-name>
<home>ejbs.haihome</home>
<remote>ejbs.haiclient</remote>
<ejb-class>ejbs.haibean</ejb-class>
<session-type>stateless</session-type>
<transaction-type>bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
<?xml version="1.0" encoding="utf-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>haiejb</ejb-name>
<jndi-name>haiejb</jndi-name>
</session>
</enterprise-beans>
</jboss>
<%@ page contenttype="text/html;charset=gbk" %>
<%@ page import="ejbs.*,javax.ejb.*,javax.naming.*,javax.rmi.portableremoteobject,java.rmi.remoteexception" %>
<html>
<body>
<% string message = "nothing!";
try {
initialcontext ic = new initialcontext();
object objref = ic.lookup("haiejb");
haihome home = (haihome) portableremoteobject.narrow(objref,ejbs.haihome.class);
haiclient hairemote = home.create();
message = hairemote.sayhai();
} catch (remoteexception re) {
re.printstacktrace();
} catch (createexception ce) {
ce.printstacktrace();
} catch (namingexception ne) {
ne.printstacktrace();
}
%>
<h1><%=message%></h1>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<!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>
<ejb-ref>
<ejb-ref-name>haiejb</ejb-ref-name>
<ejb-ref-type>session</ejb-ref-type>
<home>ejbs.haihome</home>
<remote>ejbs.haiclient</remote>
</ejb-ref>
</web-app>
<?xml version="1.0" encoding="utf-8"?>
<jboss-web>
<ejb-ref>
<ejb-ref-name>haiejb</ejb-ref-name>
<jndi-name>haiejb</jndi-name>
</ejb-ref>
</jboss-web>
<?xml version="1.0" encoding="utf-8"?>
<application>
<display-name>haiejb j2ee application</display-name>
<module>
<web>
<web-uri>haiejb.war</web-uri>
<context-root>/haiejb</context-root>
</web>
</module>
<module>
<ejb>haiejb.jar</ejb>
</module>
</application>
jboss_home/server/default/log/server.log
新闻热点
疑难解答