code/JSP

[JSP] request 객체 테스트

shallot 2017. 4. 20. 15:07
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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>request test</title>
<script language="javascript">
    document.cookie = "test=OK.";
</script>
 
</head>
<body>
    <h2 align="center">request 테스트 폼</h2>
    <hr>
    <form name="f1" action=01_1.jsp method=post>
        <table border="1" cellpadding="10" cellspacing="0" align="center">
            <tr>
                <td>이름</td>
                <td><input type="text" name=name width="15" size="10"></td>
            </tr>
            <tr>
                <td>직업</td>
                <td><select name="job"><option selected>학생</option>
                        <option>회사원</option>
                        <option>주부</option></select></td>
            </tr>
            <tr>
                <td>관심분야</td>
                <td><input type="checkbox" name="inter" value="정치">정치 <input
                    type="checkbox" name="inter" value="사회">사회 <input
                    type="checkbox" name="inter" value="정보통신">정보통신</td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="확인"
                    name="B1"> <input type="reset" value="취소" name="B2">
            </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
49
50
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    request.setCharacterEncoding("euc-kr");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title></title>
</head>
<body>
    <h2 align="center">request 테스트 결과 - 1</h2>
    <hr>
    <table border=1 cellpadding="10" cellspacing="0" align="center">
        <tr>
            <td>이름</td>
            <td><%=request.getParameter("name")%></td>
        </tr>
        <tr>
            <td>직업</td>
            <td><%=request.getParameter("job")%></td>
        </tr>
        <tr>
            <td>관심분야</td>
            <td>
                <%
                    String a1[] = request.getParameterValues("inter");
                    for (int i = 0; i < a1.length; i++) {
                        out.println(a1[i] + "<br>");
                    }
                %>
            </td>
        </tr>
    </table>
    <hr>
    <center>
        <h2>request 테스트 결과 -2</h2>
        <table>
            <tr>
                <td>1.클라이언트 IP 주소: <%=request.getRemoteAddr()%><br>
                2.요청메서드: <%=request.getMethod()%><br>
                <%Cookie cookie[] = request.getCookies();%>
                3.<%=cookie[0].getName()%>에 설정된 쿠기값: <%=cookie[0].getValue()%><br>
                4.프로토콜:<%=request.getProtocol()%></td>
            </tr>
        </table>
    </center>
</body>
</html>