Coding Note

[JSP] 학점 출력하기! 본문

Web/Jsp

[JSP] 학점 출력하기!

jinnkim 2022. 2. 3. 10:30

 

학점 출력하기!!

 

 

구현

 

 

 

 

코드

1. HTML

 

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>시험점수입력</title>
</head>
<body>
	<form method="get" action="scoreTest.jsp">
		시험점수 : <input type="text" name="score"><br>
		<input type="submit" value="변환하기">
	</form>
</body>
</html>

 

 

 

2. JSP

 

<%@ 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>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>학점출력</title>
</head>
<body>
	<h1>시험점수 : <%=score %></h1><br>
	<%
		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>

 

 

 

Comments