Send03.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Send03.html</title>
</head>
<body>
<!--
송수신실습 03
- 두개의 정수와 연산자 입력받는 html페이지
-->
<div>
<h1>연산</h1>
<hr>
</div>
<div>
<form action="Receive03.jsp" method="post">
정수1
<input type="text" name="su1">
<select name="cal">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
정수2
<input type="text" name="su2"><br>
<button type="submit">결과 확인</button>
<button type="reset">취소</button>
</form>
</div>
</body>
</html>
Receive03.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
String s1Str = request.getParameter("su1");
String s2Str = request.getParameter("su2");
double s3 = 0;
int result = 0;
double result2= 0;
String cal = request.getParameter("cal");
String msg = "";
try
{
int s1 = Integer.parseInt(s1Str);
int s2 = Integer.parseInt(s2Str);
if(cal.equals("+"))
{
result = s1+s2;
msg = String.format("입력하신 %d와 %d의 연산 결과는 %d 입니다.", s1, s2, result);
}
else if(cal.equals("-"))
{
result = s1-s2;
msg = String.format("입력하신 %d와 %d의 연산 결과는 %d 입니다.", s1, s2, result);
}
else if(cal.equals("*"))
{
result = s1*s2;
msg = String.format("입력하신 %d와 %d의 연산 결과는 %d 입니다.", s1, s2, result);
}
else if(cal.equals("/"))
{
s3 = (double)s2;
result2 = s1/s3;
msg = String.format("입력하신 %d와 %f의 연산 결과는 %.1f 입니다.", s1, s3, result2);
}
else
msg = "확인 불가";
}
catch(Exception e)
{
System.out.println(e.toString());
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Receive03.jsp</title>
</head>
<body>
<%=msg %>
</body>
</html>
728x90
'WEB Archive' 카테고리의 다른 글
[HTML] 데이터 송신하고 데이터 수신하기 (0) | 2024.08.22 |
---|---|
[HTML] 이름과 점수를 입력하고 데이터를 전송하여 수신하는 실습 (0) | 2024.08.22 |
[HTML] 회원가입 폼 만들기 (0) | 2024.08.22 |
[HTML] form.submit() 활용한 구구단 출력 (0) | 2024.08.22 |
[HTML] 데이터 송수신 실습 - 자기자신 페이지로부터 데이터 수신하기 (0) | 2024.08.22 |
댓글