long chen

Greenhorn
+ Follow
since Sep 18, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by long chen

second.jsp
<body>

<form action="Result.jsp" method="POST" >
FirstNumber:<input type="text" name="FIRSTNUMBER">

SecondNumber:<input type="text" name="SECONDNUMBER">

ADD:<input type="radio" name="result" value="ADD" >

SUB:<input type="radio" name="result" value="SUB" >

DIV:<input type="radio" name="result" value="DIV" >

MUL:<input type="radio" name="result" value="MUL" >

<input type="submit" value="Result" >

</form>

</body>
</html>

Result.jsp
<body>
<%
String Result = request.getParameter("result");
String s1 = request.getParameter("FIRSTNUMBER");
String s2 = request.getParameter("SECONDNUMBER");
int k=Integer.parseInt(s1);
if (Result.equals("ADD")) {
int add = Integer.parseInt(s1) + Integer.parseInt(s2);
out.println("Result=" + add);
} else if (Result.equals("SUB")) {
int sub = Integer.parseInt(s1) - Integer.parseInt(s2);
out.println("Result=" + sub);
} else if (Result.equals("MUL")) {
int mul = Integer.parseInt(s1) * Integer.parseInt(s2);
out.println("Result=" + mul);
} else if (Result.equals("DIV")) {
int div = Integer.parseInt(s1) / Integer.parseInt(s2);
out.println("Result = " + div);
}
%>
</body>
1. you can only getParameter from pre-page.
2. the radio should have the same name
3. "if" should have {}
14 years ago
JSP