본문 바로가기

Learning/JSP

score.jsp와 scoreResult.jsp를 이용하여 성적과 총점, 평균, 학점 출력

score.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="scoreResult.jsp">
이름: <input type="text" name="name"><br>
국어: <input type="text" name="kor"><br>
영어: <input type="text" name="eng"><br>
수학: <input type="text" name="math"><br>
<input type="submit" value="전송">
</form>
</body>
</html>
cs

 


 

scoreResult.jsp

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<%
    String name=request.getParameter("name");
    int kor=Integer.parseInt(request.getParameter("kor"));
    int eng=Integer.parseInt(request.getParameter("eng"));
    int math=Integer.parseInt(request.getParameter("math"));
    int tot=kor+eng+math;
    int avg=tot/3;
    String grade="";
    switch(avg/10){
    case 9: grade="A학점"break;
    case 8: grade="B학점"break;
    case 7: grade="C학점"break;
    default : grade="F학점"break;
    }
    out.println("name");
    out.println("kor");
    out.println("eng");
    out.println("math");
%>
<body>
결과<hr>
이름: <%=name %><br>
국어: <%=kor %><br>
영어: <%=eng %><br>
수학: <%=math %><br>
총점: <%=tot%><br>
평균: <%=avg%><br>
학점: <%=grade %><br>
</body>
</html>
cs