(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); [JSP]Application, Session, Request 예제 :: 깜냥깜냥


Application.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
<%@ 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>Application.jsp</title>
</head>
<body>
    <center>
        <h2>영역과 속성 테스트</h2>
        <form name="f1" method="post" action="Session.jsp">
            <table border="1" cellpadding="10" cellspacing="0">
                <tr>
                    <td colspan="2" align="center">Application 영역에 저장할 내용들</td>
                </tr>
                <tr>
                    <td>이름</td>
                    <td><input type="text" name="username" style="border: 0px;"
                        size="20"></td>
                </tr>
                <tr>
                    <td>아이디</td>
                    <td><input type="text" name="id" style="border: 0px;"
                        size="20"></td>
                </tr>
                <tr>
                    <td>패스워드</td>
                    <td><input type="text" name="pass" style="border: 0px;"
                        size="20"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit" value="전송"></td>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>

Session.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
45
46
47
48
49
50
51
52
<%@ 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>Session.jsp</title>
</head>
<body>
    <center>
        <h2>영역과 속성 테스트</h2>
        <%    String username=request.getParameter("username");
            String id=request.getParameter("id");
            String pass = request.getParameter("pass");
            application.setAttribute("username", username);
            application.setAttribute("id", id);
            
        %>
        <h3>${username}님
            반갑습니다.<br> ${username}님의 아이디는 ${id}입니다.
        </h3>
 
        <form name="f2" method="post" action="Save.jsp?pass=<%=pass%>">
            <table border="1" cellpadding="10" cellspacing="0">
                <tr>
                    <td colspan="2" align="center">Session 영역에 저장할 내용들</td>
                </tr>
                <tr>
                    <td>e-mail 주소</td>
                    <td><input type="text" name="email" style="border: 0px;"
                        size="30"></td>
                </tr>
                <tr>
                    <td>집주소</td>
                    <td><input type="text" name="address" style="border: 0px;"
                        size="40"></td>
                </tr>
                <tr>
                    <td>전화번호</td>
                    <td><input type="text" name="tel" style="border: 0px;"
                        size="20"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit" value="전송"></td>
                </tr>
            </table>
        </form>
</body>
</html>

Save.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
<%@ 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>Save.jsp</title>
</head>
<body>
    <center>
        <h2>영역과 속성 테스트</h2>
        <%
            String email = request.getParameter("email");
            String address = request.getParameter("address");
            String tel = request.getParameter("tel");
            String pass = request.getParameter("pass");
            application.setAttribute("username", application.getAttribute("username"));
        %>
        <%
            application.setAttribute("email", email);
            application.setAttribute("address", address);
            application.setAttribute("tel", tel);
        %>
        ${username}님의 정보가 모두 저장되었습니다.<br> <br> <a
            href="Check.jsp?pass=<%=pass%>">확인하러 가기</a>
    </center>
</body>
</html>

check.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<%@ 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>Check.jsp</title>
</head>
<body>
    <center>
        <h2>영역과 속성 테스트</h2>
        <br> <br>
        <%
            application.setAttribute("username", application.getAttribute("username"));
            application.setAttribute("id", application.getAttribute("id"));
            session.setAttribute("email", session.getAttribute("email"));
            session.setAttribute("address", session.getAttribute("address"));
            session.setAttribute("tel", session.getAttribute("tel"));
            String pass = request.getParameter("pass");
        %>
        <form>
            <table border="1" cellpadding="10" cellspacing="0">
                <tr>
                    <td colspan="2" align="center">Application 영역에 저장할 내용들</td>
                </tr>
                <tr>
                    <td>이름</td>
                    <td>${username}</td>
                </tr>
                <tr>
                    <td>아이디</td>
                    <td>${id}</td>
                </tr>
                <tr>
                    <td>패스워드</td>
                    <td><%=pass %></td>
                </tr>
            </table>
        </form>
        <br> <br>
        <form>
            <table border="1" cellpadding="10" cellspacing="0">
                <tr>
                    <td colspan="2" align="center">Session 영역에 저장할 내용들</td>
                </tr>
                <tr>
                    <td>e-mail 주소</td>
                    <td>${email}</td>
                </tr>
                <tr>
                    <td>집주소</td>
                    <td>${address}</td>
                </tr>
                <tr>
                    <td>전화번호</td>
                    <td>${tel}</td>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>


request는 get 방식에서 가져오기 힘듭니다! 그래서 action이나 경로에서 표시를 해줘야합니다.


 


+ Recent posts