학점 변환 예제
1. 다음과 같이 scoreTest.html, scoreTest.jsp 파일을 준비합니다.

2. scoreTest.html을 다음과 같이 작성합니다. 사용자로부터 시험 점수를 입력 받아 scoreTest.jsp로 전송합니다.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>시험 점수를 입력해 주세요</h1>
<form method=get action="scoreTest.jsp">
시험점수 : <input type=text name="score" /> <br>
<input type="submit" value="변환하기">
</form>
</body>
</html>
3. scoreTest.jsp를 다음과 같이 작성합니다. scoreTest.html로부터 받은 점수를 다중 if~else if문을 이용해 학점을 변환합니다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
int score = Integer.parseInt(request.getParameter("score"));
%>
<!DOCTYPE html>
<html>
<head>
<title>점수 출력창</title>
<meta charset="UTF-8">
</head>
<body>
<h1> 시험점수 <%=score %>점</h1>
<%
if (score >= 90) {
%>
<h1> A학점입니다.</h1>
<%
} else if (score >= 80 && score < 90) {
%>
<h1> B학점입니다.</h1>
<%
} else if (score >= 70 && score < 80) {
%>
<h1> C학점입니다.</h1>
<%
} else if (score >= 60 && score < 70) {
%>
<h1> D학점입니다.</h1>
<%
} else {
%>
<h1> F학점입니다.</h1>
<%
}
%>
<br>
<a href="scoreTest.html">시험점수입력</a>
</body>
</html>
4. http://localhost:8090/pro12/scoreTest.html로 요청하여 시험점수 입력창에 시험 점수를 입력한 후 변환하기를 클릭합니다.

5. 시험 점수를 학점으로 변환하여 출력합니다.

'프로그래밍 언어 > 자바 웹' 카테고리의 다른 글
| 이미지 리스트 출력 예제 (0) | 2025.10.16 |
|---|---|
| 구구단 출력 예제 (0) | 2025.10.13 |
| 스크립트 요소 이용해 실습하기 - 로그인 예제 (0) | 2025.10.07 |
| JSP 주석문 사용하기 (0) | 2025.10.04 |
| 스크립트릿 사용하기 (0) | 2025.09.28 |