JBoss 4.0 automatically integrates Tomcat 5.0, so it is not just a professional EJB container, but also a professional JSP / servlet container and web server.
Tomcat 5.0 is integrated in the JBoss's below this directory:
JBoss_Home / Server / Default / Deploy / JBossWeb-Tomcat50.SAR
A server.xml and web.xml file are provided inside, and some basic settings are available for Tomcat. But JBoss designers suggest that users don't even touch this directory, not to modify and add any files, because Tomcat is connected to JBoss, so that all settings work can be done in JBOSS own configuration files. But I still found a place worth modification: Modify the port number in Server.xml, such as the default 8080 port is changed to 4000 port, because I found that my "Baidu" software often occupies 8080 port, and I I have already had a Tomcat 5.0.
Type this:
Http: // localhost: 4000 /
Welcome page that can be accessed to JBoss
This article demonstrates how JSP pages call EJB components in JBoss 4.0.
In summary:
J2EE App / | __EJB Components / (Haiejb.jar) | | | | | | | | | | | __EJBS / | | | __HAIHOME.CLASS | | __HAICLIENT.CLASS | | __HAIBEAN. Class | __WEB Application / (Haiejb.war) | | __HAIEJB.JSP | | __WEB-INF / | | __WEB.XML | | __JBOSS-Web.xml | __META-INF / | __Application.xml
First, compile the Java file for EJB class file
Java file compilation: [Assume that javax.ejb. * package is included in the classpath of the system environment variable, the package can be found in the following places: jboss_home / server / default / lib / jboss-j2ee.jar jboss_home / client / jboss-j2ee .jar] [Java source file directory]>: javac -classpath% classpath% -d [output directory: EJB component directory] * .java haihome.java: package ejbs; import java.io.serializable; import java.rmi. * ; import javax.ejb *; public interface HaiHome extends EJBHome {HaiClient create () throws RemoteException, CreateException;} HaiClient.java:. 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 (SessionCo NTEXT SC) {}} II. Create an EJB component:
Haiejb.jar: (EJB component)
Packaged command: [EJB component directory]>: jar cvf haiejb.jar meta-inf / ejbs /
| __META-INF /
| | | __Ejb-jar.xml
| | | __JBOSS.XML
| __EJBS /
| __Haihome.class
| __HAICLIENT.CLASS
| __Haibean.class
EJB-jar.xml:
XML Version = "1.0" Encoding = "UTF-8"?>
XML Version = "1.0" Encoding = "UTF-8"?>
Third, create a web application
Haiejb.war: (web application)
Packaged command: [Web application directory]>: jar cvf haiejb.war haiejb.jsp Web-inf /
| __haiejb.jsp
| __WEB-INF /
| __web.xml
| __JBOSS-Web.xml
Haiejb.jsp:
<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ page import = "EJBS. *, javax.ejb. *, javax.naming. *, javax.rmi.portableremoteObject, java.rmi. RemoteException "%>
<% 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 ();}%>
XML Version = "1.0" encoding = "UTF-8"?>
JBoss-Web.xml:
XML Version = "1.0" encoding = "UTF-8"?>
Fourth, create a J2EE application
Haiejb.ear: (J2EE application)
Copy the haiejb.jar and haiejb.war package created above to the J2EE application home directory you created, create a new meta-inflicity and create an Application.xml file inside:
Packaged command: [J2EE application directory]>: jar cvf haiejb.ear haiejb.jar haiejb.war meta-inf /
| __haiejb.jar
| __haiejb.war
| __META-INF /
| __Application.xmlapplication.xml:
XML Version = "1.0" encoding = "UTF-8"?>
V. Deploy J2EE Application:
Copy haiejb.ear to
JBoss_Home / Server / Default / Deploy /
Start JBoss 4.0, note that there is no abnormality in the command line window, if there is an abnormal situation, check the log file:
JBoss_Home / Server / Default / log / Server.log
Find out the analysis problem, then correct it until there is no abnormal display
Finally, type in the browser address bar:
Http: // localhost: 8080 / haiejb / haiejb.jsp
result:
Hai, EJB TECHNOLOGY!