3.Arithmetic operations implemented in session bean

MySessionBean.java :-
package com.ejb;
import javax.ejb.Stateless;
public class MySessionBean implements MySessionBeanRemote
public int add(int a, int b) {
return a+b;
public int sub(int a, int b) {
return a-b;
public int mul(int a, int b) {
return a*b;
public int div(int a, int b) {
return a/b;

MySessionBeanRemote.java :-
package com.ejb;
import javax.ejb.Remote;
public interface MySessionBeanRemote
int add(int a, int b);
int sub(int a, int b);
int mul(int a, int b);
int div(int a, int b);

index.jsp :-
<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<form action=”test” method=”post”>
<table border=”1″>
<th colspan=”2″>Calculator</th>
<td>Enter 1st number </td>
<td><input type=”text” name=”t1″ value=”” /></td>
<td>Enter 2nd number </td>
<td><input type=”text” name=”t2″ value=”” /></td>
<td colspan=”2″>
<input type=”radio” name=”rdogrp” value=”Add” checked=”checked” />Add
<input type=”radio” name=”rdogrp” value=”Subtract” />Subtract
<input type=”radio” name=”rdogrp” value=”Multiply” />Multiply
<input type=”radio” name=”rdogrp” value=”Divide” />Divide </td>
<td colspan=”2″ align=”center”>
<input type=”submit” value=”Click to see the result” name=”b1″ align=”center” /> </td>

test.java :-
import com.ejb.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class test extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
MySessionBean bean = new MySessionBean();
int a = Integer.parseInt(request.getParameter(“t1”));
int b = Integer.parseInt(request.getParameter(“t2”));
String s = request.getParameter(“rdogrp”);
out.println(“Result :- ” + bean.add(a, b));
else if(s.equals(“Subtract”))
out.println(“Result :- ” + bean.sub(a, b));
else if(s.equals(“Multiply”))
out.println(“Result :- ” + bean.mul(a, b));
else if(s.equals(“Divide”))
out.println(“Result :- ” + bean.div(a, b));
} finally {