EJB – ARITHMETIC OPERATION


AIM:
    To write a Java application for bank accounts using visibroker.

ALGORITHM:
Step 1: Start
Step 2: Go to File => New Project and choose Enterprise from categories and select Enterprise
           Application from project
Step 3: Name the project name as ejb1 and click on next and finish
Step 4: In project name tab, right click on the ejb1-ejb & choose New => Session bean
Step 5: Name the EJB name as ejb1class & package name as ejbpack and click on stateless in
           Session type & check the remote in create interface
Step 6: Right click on the coding area and select EJB Methods => Add Business Method
Step 7: Name the business method as add and return type as java.lang.Integer and add parameters
    x, y & their type as int and click on ok button 
Step 8: In ejb1classBean.java under add function change return NULL to return x+y
Step 9: In projects tab right click on ejb1-war & choose New => select [servlet]
Step 10: Name class name as ejb1servlet and package as ejb1pack and click on next and finish
Step 11: Add the necessary  imports to the ejb1servlet java code under doget()
Step 12: Compile the ejb1servlet.java program
Step 13: In project tab, under ejb1-war click on webpages => index.jsp
Step 14: Replace the code on the “Hello World” statement
Step 15: Save and Run the project then the designed output will be displayed
Step 16: Stop

SOURCE CODE:

ejb1servlet.java
package ejb1pack;
import java.io.*;

import java.net.*;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;
public class ejb1servlet extends HttpServlet {
@EJB
private ejb1classRemote ob;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        int a=Integer.parseInt(request.getParameter("one")); 
        int b=Integer.parseInt(request.getParameter("two"));
       out.println(ob.add(a,b));   
    }


index.jsp
<form action="ejb1servlet" method="get">
                ENTER FIRST NUMBER &nbsp;
            <input type="text" name="one" value="" /><br>
ENTER SECOND NUMBER &nbsp;
           <input type="text" name="two" value="" /><br>
<input type="submit" value="submit" />
</form>

OUTPUT:





RESULT:
          Thus the EJB bean Java program for arithmetic operation was performed using servlets and the output was verified.

.
Previous
Next Post »

Still not found what you are looking for? Try again here.