You are on page 1of 2

Enterprise Java Beans 

Creating the project: 

1) Add the Sun Java Application Server by choosing “Add Server” option in Runtime tab (If 
server is not available). 
2) Choose New Project from file menu. 
3) Create a new Enterprise Application project by choosing Enterprise category. 
4) Choose appropriate project and folder name. 
Project name:  HelloApp 
Project Location: Z:\EJB\ 
Click Finish. 

Creating and coding the bean: 

5) Now right click the EJB module of the enterprise application project. 
6) In the context menu choose Session Bean. 
7) In the dialog box that appears enter the EJB name. The type should be stateless. A 
suitable package name should also be given. 
EJB Name: Hello 
Package: myejb 
8) Now in the editor pane the Bean class of the EJB opens.(HelloBean.java in this case) 
9) In the context menu choose Add business method option in EJB Methods menu item. 
10) Now the “Add Business Method” dialog appears. Enter the method name and return 
values. 
Name: sayHello 
Return Type: String 
11) To add parameter click the add button. Enter parameter name, return type and click ok. 
Parameter1: 
  Name: str 
  Type: String 
12) Define the business method. 
return "Hello "+str; 

Creating the client resources: 

13) Now right click the web module to obtain the context menu. Choose Servlet. 
14) Enter the servlet name and package name and click Finish. 
Servlet Name:HelloServlet 
Package Name:myweb 
15) Remove the comment surrounding the dynamic html content in the processRequest 
method. 
Line 30 & Line 39 
16) Right click the servlet editor and choose Call Enterprise Bean from Enterprise Resources. 
In the dialog box that appers choose the Bean shown (HelloSB here). 
17) Now a lookup method is added to the class (lookupHelloBean here). 
18) Get the user input from JSP by using request.getParameter method. 
String str=request.getParameter(“text1”); 
19) Call the lookup method and assign it to the Local interface of the EJB inside the 
processRequest method. 
HelloLocal h=lookupHelloBean(); 
20) The remote method can now be invoked by using the local interface. 
out.println(“<h2>”+h.sayHello(str)+”<\h2>”); 
21) Now open the index.jsp present in the web module. 
22) Add a form name it, set the method as post and action should target to the servlet. 
Form name: Form1 
Action: HelloServlet 
23) Add a text box and a submit button to the page and name them appropriately. 
Text box name: text1 
Button Name: button1 

Deploying and running the application: 

24) Close NetBeans IDE. 
25) Start the server by typing asadmin start‐domain domain1 in bin folder of the application 
server. 
26) To check server status open IE and type http://localhost:8080. A page showing server 
running message is displayed. 
27) Now open server’s admin console by typing http://localhost:4848. 
28) Choose deploy enterprise application ear from common task. 
29) In the page that appears choose the ear file from the dist directory of the application. 
30) Click next and deploy the project. 

You might also like