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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<%@ 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>
<script>
function check(){
    if(document.getElementById("name").value==""){
        alert("이름을 입력하세요");
        return;
    }
    if(document.getElementById("studentNum").value==""){
        alert("학번을 입력하세요");
        return;
    }
    var obj=document.getElementsByName("hobby");
    var checkCnt=false;
    for(i=0;i<obj.length;i++){
        if(obj[i].checked){
            checkCnt=true;    
        }
    }
    if(checkCnt==false){
        alert("취미를 선택하세요");
        return;
    }
    frm.submit(); //직접 submit()이라는 메소드를 호출. 액션을 들고 가줌
}
</script>
</head>
<body>
<form action="inputResult.jsp" method="post" name="frm"> 
<!--method="post"하면 선택된 값들이 주소창에 안보임--> <!--method="get"하면 주소창에 선택값들이 표시됨 -->
이름: <input type="text" name="name" id="name"><br> <!-- DOM방식은 id로 접근 -->
학번: <input type="text" name="studentNum" id="studentNum"><br>
성별: 
<!-- 
<input type="radio" name="gender" value="man" checked>남자
<input type="radio" name="gender" value="woman">여자<br>
-->
<input type="radio" name="gender" value="man" checked  id="man">
<label for="man">남자</label> <!-- id, label을 이용하여 글자를 클릭해도 선택됨 -->
<input type="radio" name="gender" value="woman" checked  id="woman">
<label for="woman">여자</label><br>
전공: 
<select name="major">
    <option value="국문학과" selected>국문학과</option>
    <option value="영문학과">영문학과</option>
    <option value="수학과" >수학과</option>
    <option value="정치학과">정치학과</option>
    <option value="체육학과">체육학과</option>
</select>
<br>
취미<br>
<input type="checkbox" name="hobby" value="운동">운동
<input type="checkbox" name="hobby" value="운동1">운동1
<input type="checkbox" name="hobby" value="운동2">운동2
<input type="checkbox" name="hobby" value="운동3">운동3
<input type="checkbox" name="hobby" value="운동4">운동4 <br>
<input type="button" value="보내기" onclick="check()"> 
<!-- submit=form안에 있는 값들을 들고 액션한테 가라는 뜻. 그전에 검사하기-->
<!-- button=모양만 버튼. 아무 역할이 없음. 그래서 뒤에 onclick="check()"-->
<input type="reset" value="취소">
</form>
</body>
</html>
cs

 


 

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
<%@ 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>
<%
    request.setCharacterEncoding("utf-8");
%>
<jsp:useBean id="student" class="com.exam.StudentBean"/> 
<!-- jsp의 액션태그. StudentBean의 student객체를 만드는 것과 같음-->
<jsp:setProperty property="*" name="student"/>
<!-- id와 name을 동일하게. 데이터들이 연결되도록 -->
<%
    String[]h=student.getHobby();
    String strHobby="";
    for(int i=0;i<h.length;i++){
        strHobby+=h[i]+" ";
    }
%>
</head>
<body>
이름: <jsp:getProperty property="name" name="student"/>
<!-- student 객체의 name을 가져오기 -->
<hr>
이름: <%=student.getName() %> <br>
학번: <%=student.getStudentNum() %> <br>
성별: <%=student.getGender() %> <br>
전공: <%=student.getMajor() %> <br>
취미: <%=strHobby %>
</body>
</html>
cs

 

 

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
39
40
package com.exam;
 
public class StudentBean {
    private String name; //이름
    private String studentNum; //학번
    private String gender; //성별
    private String major; //전공
    private String[] hobby; //취미
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getStudentNum() {
        return studentNum;
    }
    public void setStudentNum(String studentNum) {
        this.studentNum = studentNum;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getMajor() {
        return major;
    }
    public void setMajor(String major) {
        this.major = major;
    }
    public String[] getHobby() {
        return hobby;
    }
    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }
}
cs

 

 

 

 

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
39
40
41
42
<%@ 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>
<script>
    function test(){
        if(document.getElementById("name").value==""){
            alert("이름을 입력하세요");
            return;
        }
        if(document.getElementById("kor").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("국어성적을 입력하세요"); //isNaN: 문자인지 아닌지 판별
            return;
        }
        if(document.getElementById("eng").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("영어성적을 입력하세요");
            return;
        }
        if(document.getElementById("math").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("수학성적을 입력하세요");
            return;
        }
        document.getElementById("frm").submit();
    }
</script>
</head>
<body>
<form action="scoreResult3.jsp" id="frm">
이름: <input type="text" name="name" id="name"><br>
국어: <input type="text" name="kor" id="kor"><br>
영어: <input type="text" name="eng" id="eng"><br>
수학: <input type="text" name="math" id="math"><br>
<input type="button" value="전송" onclick="test()">
</form>
</body>
</html>
cs

 

 

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
<%@page import="com.exam.ScoreBean3"%>
<%@ 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>
<%
    request.setCharacterEncoding("utf-8");
    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"));
    ScoreBean3 sb=new ScoreBean3(name,kor,eng,math); //생성자를 이용하여 값 할당
    
%>
</head>
<body>
<!-- scoreResult3.jsp -->
scoreResult3.jsp<br>
이름: <%=sb.getName() %><br>
국어: <%=sb.getKor() %><br>
영어: <%=sb.getEng() %><br>
수학: <%=sb.getMath() %><br>
총점: <%=sb.getTot() %><br>
평균: <%=sb.getAvg() %><br>
학점: <%=sb.getGrade() %>
</body>
</html>
cs

 

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
39
40
41
42
43
44
45
46
47
48
package com.exam;
 
public class ScoreBean3 {
    private String name;
    private int kor;
    private int eng;
    private int math;
    
    //getter
    public String getName() {
        return name;
    }
    public int getKor() {
        return kor;
    }
    public int getEng() {
        return eng;
    }
    public int getMath() {
        return math;
    }
    
    //생성자 source-Generate Constructor using Fields...
    public ScoreBean3(String name, int kor, int eng, int math) {
        super();
        this.name = name;
        this.kor = kor;
        this.eng = eng;
        this.math = math;
    }
    public int getTot() {
        return (kor+eng+math);
    }
    public int getAvg() {
        return (kor+eng+math)/3;
    }
    public String getGrade() {
        String grade="";
        switch((kor+eng+math)/3/10) {
            case 10:
            case 9: grade="A학점"break;
            case 8: grade="B학점"break;
            case 7: grade="C학점"break;
            default: grade="F학점"break;
        }
        return grade;
    }
}
cs
  • score2.jsp/scoreResult2.jsp 두 JSP 파일과 ScoreBean 자바파일 만들기.

  • 생성자와 객체를 생성하고 메소드를 호출하기. 이름과 국영수 성적을 인터넷 페이지에 출력.

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
39
40
41
42
<%@ 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>
<script>
    function test(){
        if(document.getElementById("name").value==""){
            alert("이름을 입력하세요");
            return;
        }
        if(document.getElementById("kor").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("국어성적을 입력하세요"); //isNaN: 문자인지 아닌지 판별
            return;
        }
        if(document.getElementById("eng").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("영어성적을 입력하세요");
            return;
        }
        if(document.getElementById("math").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("수학성적을 입력하세요");
            return;
        }
        document.getElementById("frm").submit();
    }
</script>
</head>
<body>
<form action="scoreResult2.jsp" id="frm">
이름: <input type="text" name="name" id="name"><br>
국어: <input type="text" name="kor" id="kor"><br>
영어: <input type="text" name="eng" id="eng"><br>
수학: <input type="text" name="math" id="math"><br>
<input type="button" value="전송" onclick="test()">
</form>
</body>
</html>
cs

 

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
<%@page import="com.exam.ScoreBean"%>
<%@ 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>
<%
    request.setCharacterEncoding("utf-8");
    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"));
    ScoreBean sb=new ScoreBean();
    sb.setName(name);
    sb.setKor(kor);
    sb.setEng(eng);
    sb.setMath(math);
%>
</head>
<body>
<!-- scoreResult2.jsp -->
scoreResult2.jsp
이름: <%=sb.getName() %><br>
국어: <%=sb.getKor() %><br>
영어: <%=sb.getEng() %><br>
수학: <%=sb.getMath() %><br>
총점: <%=sb.getTot() %><br>
평균: <%=sb.getAvg() %><br>
학점: <%=sb.getGrade() %>
</body>
</html>
cs

 

 

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
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.exam;
 
public class ScoreBean {
    private String name;
    private int kor;
    private int eng;
    private int math;
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getKor() {
        return kor;
    }
    public void setKor(int kor) {
        this.kor = kor;
    }
    public int getEng() {
        return eng;
    }
    public void setEng(int eng) {
        this.eng = eng;
    }
    public int getMath() {
        return math;
    }
    public void setMath(int math) {
        this.math = math;
    }
    
    public int getTot() {
        return (kor+eng+math);
    }
    public int getAvg() {
        return (kor+eng+math)/3;
    }
    public String getGrade() {
        String grade="";
        switch((kor+eng+math)/3/10) {
            case 10:
            case 9: grade="A학점"break;
            case 8: grade="B학점"break;
            case 7: grade="C학점"break;
            default: grade="F학점"break;
        }
        return grade;
    }
}
cs

 

  • 자바스크립트에서도 자바처럼 함수를 호출하여 인터넷 페이지에 출력할 수 있다.

  • dateExam.jsp, DateBean.java

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%@page import="com.exam.DateBean"%>
<%@ 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>
<%
    DateBean bean=new DateBean();
%>
<%=bean.getToday()%>
<hr>
<%=bean.getDay() %>
</body>
</html>
cs

 


 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.exam;
import java.util.Calendar;
public class DateBean {
    Calendar ca=Calendar.getInstance();
    String[]arr= {"일","월","화","수","목","금","토"};
    
    public String getToday() {
        String str=ca.get(Calendar.YEAR)+"년";
        str+=ca.get(Calendar.MONDAY)+1+"월";
        str+=ca.get(Calendar.DATE)+"일";
        str+=arr[ca.get(Calendar.DAY_OF_WEEK)-1]+"요일";
        return str;
    }
    public String getDay() {
        StringBuilder sb=new StringBuilder(); //문자열이 계속 바뀌는 상황에선 StringBuilder가 유용(동적인 문자열)
        sb.append(ca.get(Calendar.YEAR)+"년");
        sb.append(ca.get(Calendar.MONDAY)+1+"월");
        sb.append(ca.get(Calendar.DATE)+"일");
        sb.append(arr[ca.get(Calendar.DAY_OF_WEEK)-1]+"요일");
        return sb.toString(); 
    }
}
 
 
cs

 

  • 캘린더 함수를 이용하여 오늘 날짜 출력하기

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
39
40
41
42
43
44
45
46
47
48
49
50
<%@page import="java.util.Calendar"%>
<%@ 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>
<%
Calendar ca=Calendar.getInstance();
String[]arr={"일요일","월요일","화요일","수요일","목요일","금요일","토요일"};
String day="";
switch(ca.get(Calendar.DAY_OF_WEEK)){
    case 1: day="일요일"break
    case 2: day="월요일"break;
    case 3: day="화요일"break;
    case 4: day="수요일"break;
    case 5: day="목요일"break;
    case 6: day="금요일"break;
    case 7: day="토요일"break;
}
%>
<%!
public String getDay(int x){
    String str="";
    switch(x){
        case 1: str="일요일"break
        case 2: str="월요일"break;
        case 3: str="화요일"break;
        case 4: str="수요일"break;
        case 5: str="목요일"break;
        case 6: str="금요일"break;
        case 7: str="토요일"break;
    }
    return str;
}
%>
</head>
<body>
오늘은 <%=ca.get(Calendar.YEAR) %>
<%=ca.get(Calendar.MONTH)+1 %>
<%=ca.get(Calendar.DATE) %>
<%=day %>
<hr>
배열요일:
<%=arr[ca.get(Calendar.DAY_OF_WEEK)-1]%>
<hr>
함수요일: <%=getDay(ca.get(Calendar.DAY_OF_WEEK))%>
</body>
</html>
cs

 

  • 이름, 국어, 영어, 수학 점수가 빈칸일 경우 오류 메시지 띄우기

 

 

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
39
40
41
42
<%@ 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>
<script>
    function test(){
        if(document.getElementById("name").value==""){
            alert("이름을 입력하세요");
            return;
        }
        if(document.getElementById("kor").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("국어성적을 입력하세요"); //isNaN: 문자인지 아닌지 판별
            return;
        }
        if(document.getElementById("eng").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("영어성적을 입력하세요");
            return;
        }
        if(document.getElementById("math").value==""
                ||isNaN(document.getElementById("kor").value)){
            alert("수학성적을 입력하세요");
            return;
        }
        document.getElementById("frm").submit();
    }
</script>
</head>
<body>
<form action="scoreResult.jsp" id="frm">
이름: <input type="text" name="name" id="name"><br>
국어: <input type="text" name="kor" id="kor"><br>
영어: <input type="text" name="eng" id="eng"><br>
수학: <input type="text" name="math" id="math"><br>
<input type="button" value="전송" onclick="test()">
</form>
</body>
</html>
cs

 

 

 


 

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
39
<%@ 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 10
    case 9: grade="A학점"break;
    case 8: grade="B학점"break;
    case 7: grade="C학점"break;
    default : grade="F학점";
    }
    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

 

 

  • 자바스크립트에서 객체 접근방식

    • BOM: 브라우저에서 오브젝이 표현되는 방식

    • DOM: 도큐먼트, HTML 트리구조 (id)로 접근

  • 요즘에는 자바스크립트와 관련된 파일들의 라이브러리 모임=jquery로도 많이 접근

 


  • 이름, 학번이 빈칸일 경우 오류메시지 띄우기

 

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<%@ 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>
<script>
function check(){
    if(document.getElementById("name").value==""){
        alert("이름을 입력하세요");
        return;
    }
    if(document.getElementById("studentNum").value==""){
        alert("학번을 입력하세요");
        return;
    }
    frm.submit(); //직접 submit()이라는 메소드를 호출. 액션을 들고 가줌
}
</script>
</head>
<body>
<form action="output.jsp" method="post" name="frm"> 
<!--method="post"하면 선택된 값들이 주소창에 안보임--> <!--method="get"하면 주소창에 선택값들이 표시됨 -->
이름: <input type="text" name="name" id="name"><br> <!-- DOM방식은 id로 접근 -->
학번: <input type="text" name="studentNum" id="studentNum"><br>
성별: 
<!-- 
<input type="radio" name="gender" value="man" checked>남자
<input type="radio" name="gender" value="woman">여자<br>
-->
<input type="radio" name="gender" value="man" checked  id="man">
<label for="man">남자</label> <!-- id, label을 이용하여 글자를 클릭해도 선택됨 -->
<input type="radio" name="gender" value="woman" checked  id="woman">
<label for="woman">여자</label><br>
전공: 
<select name="major">
    <option value="국문학과" selected>국문학과</option>
    <option value="영문학과">영문학과</option>
    <option value="수학과" >수학과</option>
    <option value="정치학과">정치학과</option>
    <option value="체육학과">체육학과</option>
</select>
<br>
취미<br>
<input type="checkbox" name="hobby" value="운동">운동
<input type="checkbox" name="hobby" value="운동1">운동1
<input type="checkbox" name="hobby" value="운동2">운동2
<input type="checkbox" name="hobby" value="운동3">운동3
<input type="checkbox" name="hobby" value="운동4">운동4 <br>
<input type="button" value="보내기" onclick="check()"> 
<!-- submit=form안에 있는 값들을 들고 액션한테 가라는 뜻. 그전에 검사하기-->
<!-- button=모양만 버튼. 아무 역할이 없음. 그래서 뒤에 onclick="check()"-->
<input type="reset" value="취소">
</form>
</body>
</html>
cs

 

 

 


 

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
<%@ 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>
<%
request.setCharacterEncoding("utf-8"); //method가 post라도 한글이 안깨짐
    String[] hobby=request.getParameterValues("hobby");
%>
<body>
결과 <hr>
이름: <%=request.getParameter("name") %><br>
학번: <%=request.getParameter("studentNum") %><br>
성별: <%=request.getParameter("gender") %><br>
전공: <%=request.getParameter("major")%><br>
<%
    String str="";
    if(hobby!=null){
        for(int i=0;i<hobby.length;i++){
        str+=hobby[i]+" ";
        }
    }
%>
취미: <%=str%>
</body>
</html>
cs

 

 

 

 

 

  • 테이블 폼 구현하여 성명, 성별, 생일, 프로그램, 여행지, 장래희망 작성하고 전송하기

 

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
table{
    width: 600px;
    heigh: 400px;
}
table, th, td{
    border: 1px solid gray;
}
th.thColor{
    background-color: skyblue;
}
ol.olType{
    list-style-type: upper-roman;
}
</style>
<table>
</head>
<body>
<form action="introProc.jsp" method="post">
    <tr>
        <th>성명</th>
        <td><input type=text name=name></td>
        <th>성별</th>
        <th><input type=radio name="man" value="남" checked id="남"> 
            <label for="남"></label>
            <input type=radio name="man" value="여" checked id="여">
            <label for="여"></label></th>
    </tr>
    <tr>
        <th>생년월일</th>
        <td colspan=3><input type=text name=year size=15>
        <input type=text name=month  size=5>
        <input type=text name=day size=5>
        <input type="radio" name="yy" value="양력" checked  id="양력">
        <label for="양력">양력</label>
        <input type="radio" name="yy" value="음력" checked id="음력">
        <label for="음력">음력</label></td>
    </tr>
    <tr>
        <th>주소</th>
        <td colspan=3><input type=text size=55 name=addr ></td>
    </tr>
    <tr>
        <th>전화번호</th>
        <td colspan=3><input type=text size=15 name=phone> - <input type=text size=15 name=phone1 > - <input type=text size=15 name=phone2 ></td>
    </tr>
    <tr>
        <th colspan=4 class="thColor">사용가능한 프로그램 선택하기</th>
    </tr>
    <tr>
        <td colspan=4>
            <ol class="olType">
                <li><input type=checkbox name="pgm" value="한글">한글
                <li><input type=checkbox name="pgm" value="포토샵">포토샵
                <li><input type=checkbox name="pgm" value="매크로 미디어 디렉터">매크로 미디어 디렉터
                <li><input type=checkbox name="pgm" value="드림위버">드림위버
                <li><input type=checkbox name="pgm" value="3D MAX">3D MAX</li>
            </ol>
        </td>
    </tr>
    <tr>
        <th colspan=4 class="thColor">가고싶은 여행지를 모두 선택하세요.</th>
    </tr>
    <tr>
        <td colspan=4><select size=3 name=play multiple>
                <option value="설악산" selected>설악산
                <option value="경포대">경포대
                <option value="토발">토발
                <option value="거제도">거제도
                <option value="변산반도">변산반도
                <option value="단양8경">단양8경
                </select>
        </td>
    </tr>
    <tr>
        <th colspan=4 class="thColor">미래의 꿈은 어떠한가요</th>
    </tr>   
    <tr>
        <td colspan=4>
            <textarea cols=50 rows=5 name="memo">미래의 꿈은 희망입니다.</textarea>
    </tr>
    <tr>
        <th colspan=4><input type=submit  value="전송" ><input type=reset name=reset value="다시쓰기"></th>
    </tr>
</table>
</form>
</body>
</html>

 


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
39
40
41
42
43
44
45
46
47
48
<%@ 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>
<%
    request.setCharacterEncoding("utf-8");
    String[] pgm=request.getParameterValues("pgm");
    String[] play=request.getParameterValues("play");
%>
<body>
결과<hr>
성명: <%=request.getParameter("name")%><br>
성별: <%=request.getParameter("man")%><br>
생년월일:
<%=request.getParameter("year")%>-
<%=request.getParameter("month")%>-
<%=request.getParameter("day")%>-
<%=request.getParameter("yy")%>
<br>
주소: <%=request.getParameter("addr")%><br>
전화번호:
<%=request.getParameter("phone")%>-
<%=request.getParameter("phone1")%>-
<%=request.getParameter("phone2")%>
<br>
<
    String str="";
    if(pgm!=null){
        for(int i=0;i<pgm.length;i++){
            str+=pgm[i]+" ";
        }
    }
    String strP="";
    if(play!=null){
        for(int i=0;i<play.length;i++){
            strP+=play[i]+" ";
        }
    }
%>
프로그램: <%=str%><br>
여행지: <%=strP%><br>
장래희망: <%=request.getParameter("memo")%>
</body>
</html>

 


 

 

input.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
39
40
41
42
43
<%@ 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="output.jsp" method="get"> 
<!--method="post"하면 선택된 값들이 주소창에 안보임-->
<!--method="get"하면 주소창에 선택값들이 표시됨 -->
이름: <input type="text" name="name"><br>
학번: <input type="text" name="studentNum"><br>
성별:
<!--
<input type="radio" name="gender" value="man" checked>남자
<input type="radio" name="gender" value="woman">여자<br>
-->
<input type="radio" name="gender" value="man" checked  id="man">
<label for="man">남자</label> <!-- id, label을 이용하여 글자를 클릭해도 선택됨 -->
<input type="radio" name="gender" value="woman" checked  id="woman">
<label for="woman">여자</label><br>
전공:
<select name="major">
    <option value="국문학과" selected>국문학과</option>
    <option value="영문학과">영문학과</option>
    <option value="수학과" >수학과</option>
    <option value="정치학과">정치학과</option>
    <option value="체육학과">체육학과</option>
</select>
<br>
취미<br>
<input type="checkbox" name="hobby" value="운동">운동
<input type="checkbox" name="hobby" value="운동1">운동1
<input type="checkbox" name="hobby" value="운동2">운동2
<input type="checkbox" name="hobby" value="운동3">운동3
<input type="checkbox" name="hobby" value="운동4">운동4 <br>
<input type="submit" value="보내기">
<input type="reset" value="취소">
</form>
</body>
</html>
cs

 

 


output.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
<%@ 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[] hobby=request.getParameterValues("hobby");
%>
<body>
결과 <hr>
이름: <%=request.getParameter("name") %><br>
학번: <%=request.getParameter("studentNum") %><br>
성별: <%=request.getParameter("gender") %><br>
전공: <%=request.getParameter("major")%><br>
<%
String str="";
for(int i=0;i<hobby.length;i++){
    str+=hobby[i]+" ";
}
%>
취미: <%=str%>
</body>
</html>
cs
 

 

 


 

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

 

 

+ Recent posts