Passing calculation result to JSP page
Index.jsp takes two input number and after submit the request go to
Operation.java. It has a radio button to select Operation. Both inputs and
radio button are submitted to Operation.java.
<form action="Operation">
First number::<input type="text" name="firstno"></input>
Second number::<input type="text" name="Secondno"></input>
<input type="radio" name="option" value="add">Add</input>
<input type="radio" name="option" value="substract">Subtract</input>
<input type="radio" name="option" value="mul">Multiply</input>
<input type="radio" name="option" value="divide">Divide</input>
<input type="submit" value="submit">
</form>
Operation.java(Servlet) takes value from input button and do calculation
based on the radio button click. It will calculate the result.
int result1=0;
int n1=Integer.parseInt(request.getParameter("firstno"));
int n2=Integer.parseInt(request.getParameter("Secondno"));
String radio=request.getParameter("option");
if(radio.equals("add"))
{
result1=n1+n2;
}
else if(radio.equals("substract"))
{
result1=n1-n2;
}
else if(radio.equals("mul"))
{
result1=n1*n2;
}
After calculation I want to show the result on the index.jsp. How can I do
that?
No comments:
Post a Comment