CalForm.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Simple Calculator</title>
</head>
<body>
<form action="CalResult.jsp" method="post">
<input type="text" name="number1" size="6">
<select name="operation">
<option value="add">+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="div">/</option>
</select>
<input type="text" name="number2" size="6">
=
<input type="submit" value="결과 확인" size="6">
</form>
</body>
</html>
CalResult.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Result</title>
</head>
<body>
<%
int number1 = Integer.parseInt(request.getParameter("number1"));
int number2 = Integer.parseInt(request.getParameter("number2"));
if(request.getParameter("operation").equals("add"))
out.print(number1+number2);
else if(request.getParameter("operation").equals("sub"))
out.print(number1-number2);
else if(request.getParameter("operation").equals("mul"))
out.print(number1*number2);
else if(request.getParameter("operation").equals("div"))
out.print(number1/number2);
%>
</body>
</html>
result)
댓글 없음:
댓글 쓰기