[JSP] request 내장객체

Web/JSP&Servlet 2018. 10. 24. 11:35





입력 UI

결과 UI


입력받는 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
44
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Request 테스트 폼</title>
</head>
<body>
    <form action="requestget.jsp" method="post">
        <div align="center">
            <h2>request 테스트 폼</h2>
            <hr>
            <form>
                <table border=1 wnameth="400" cellpadding="5">
                    <tr>
                        <td>이름</td>
                        <td><input type="text" name="name" size="15"></td>
                    </tr>
                    <tr>
                        <td>직업</td>
                        <td><select name="job">
                                <option value="전문직">전문직</option>
                                <option value="학생">학생</option>
                                <option value="공무원">공무원</option>
                                <option value="인턴">인턴</option>
                        </select></td>
                    </tr>
                    <tr>
                        <td>관심분야</td>
                        <td><input type="checkbox" name="interests" value="정치" size="15">정치
                            <input type="checkbox" name="interests" value="사회" size="15">사회 
                            <input type="checkbox" name="interests" value="정보통신" size="15">정보통신</td>
                    </tr>
                    <tr align="center">
                        <td colspan="2">
                        <input type="submit" value="확인">
                        <input type="button" value="취소"></td>
                    </tr>
                </table>
        </div>
    </form>
</body>
</html>
cs

결과출력 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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%
    request.setCharacterEncoding("UTF-8");
%>
<meta charset="UTF-8">
<title>requestget</title>
 
</head>
<body>
<h2>REQUEST 테스트 결과 - 2</h2>
    <%
        String[] interests = request.getParameterValues("interests");
    %>
    
    이름 : <%=request.getParameter("name")%> <br
    직업 : <%=request.getParameter("job")%> <br>
    관심분야 :
    <%
        for (int i = 0; i < interests.length; i++) {
    %>
    <%=interests[i]%>
    <%
        }
    %>
</body>
</html>
cs