Write a java servlet to read two parameters ?

Write a java servlet which reads two parameters from the web page,say,value 1 and value 2,which are of type integers,and finds the sum of the two values and return back the result as a web page

Showing Answers 1 - 1 of 1 Answers

kamal Mehta

  • Dec 11th, 2011
 

String value1=request.getParameter("value 1");
String value2=request.getParameter("value 2");
Int sum;
Int val1=Integer.parseInt("value1");
Int val2=Integer.parseInt("value2");
sum=val1+val2;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");

out.println("");
out.println("Sum");
out.println("");
out.println("");
out.println("

Congratulations..........


");
out.println("

"+sum+"

");

out.println("");
out.println("");
out.close();
Code
  1. span style="color: #0000ff;">"value 1""value 2""value1""value2");

  2. sum=val1+val2;

  3.     response.setContentType("text/html""<html>""<head>""<title>Sum</title>""</head>""<body>""<h1>Congratulations..........</h1><br>""<h1>"+sum+"</h1>""</body>""</html>");

  4.                 out.close();

  5.        

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions