forked from ravi2krishna/JavaWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
56 lines (43 loc) · 1.3 KB
/
Calculator.java
File metadata and controls
56 lines (43 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mypackage;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Calculator extends HttpServlet
{
public long addFucn(long first, long second){
return first+second;
}
public long subFucn(long first, long second){
return second-first;
}
public long mulFucn(long first, long second){
return first*second;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
int a1= Integer.parseInt(request.getParameter("n1"));
int a2= Integer.parseInt(request.getParameter("n2"));
if(request.getParameter("r1")!=null)
{
out.println("<h1>Addition</h1>"+addFucn(a1, a2));
}
if(request.getParameter("r2")!=null)
{
out.println("<h1>Substraction</h1>"+subFucn(a1, a2));
}
if(request.getParameter("r3")!=null)
{
out.println("<h1>Multiplication</h1>"+mulFucn(a1, a2));
}
RequestDispatcher rd=request.getRequestDispatcher("/index.jsp");
rd.include(request, response);
}
catch(Exception e)
{
}
}
}