19.04.30 JSP 페이지 액션 태그 (동영상 17강~21강)

Back-End/JSP 2019. 4. 30. 13:38
728x90
반응형

-JSP 페이지 액션 태그-



액션태그명


 액션 태그

설명       


include


<jsp:include>

다른 페이지의 실행 결과를 현재의 페이지에 포함 시킬때 사용


forward


<jsp:forward>

페이지 사이의 제어를 이동시킬 때 사용


plug-in


<jsp:plug-in>

웹 브라우저에서 자바 애플릿을 실행시킬 때 사용


useBean


<jsp:useBean>

자바빈을 JSP 페이지에서 사용할 때 사용


setProperty


<jsp:setProperty>

프로퍼티의 값을 세팅할 때 사용


getProperty


<jsp:getProperty>

프로퍼티의 값을 얻어낼 때 사용



-include 예제 및 출력 결과-


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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
 
    <center>
        <table border="1" width="800">
            <!-- Top -->
            <tr height="150">
                <!-- include액션태그를 사용 각 부분별로 파일을 불러옴 -->
                <!-- jsp:param 은 원하는 페이지에 값을 넘겨줄수 있다. -->
                <td align="center" colspan="2"><jsp:include page="Top.jsp">
                        <jsp:param value="aaa" name="id" />
                    </jsp:include> <%-- <%@ include file = "Top.jsp" %> --%></td>
            </tr>
 
            <!-- Left -->
            <tr height="400">
                <td align="center" width="200"><jsp:include page="Left.jsp" />
                </td>
 
 
 
                <!-- Center -->
                <td align="center" width="600"><jsp:include page="Center.jsp" />
                </td>
            </tr>
 
            <!-- Bottom -->
            <tr height="100">
                <td align="center" colspan="2"><jsp:include page="Bottom.jsp" />
                </td>
            </tr>
 
 
 
        </table>
    </center>
    </div>
</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
<%@ 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>
<body>
    <!-- Top -->
    <table width="800">
        <tr height="100">
            <!-- 로고 이미지 -->
            <td colspan="2" align="center" width="260"><img alt=""
                src="img/a.png" width="200" height="70"></td>
 
            <td colspan="4" align="center"><font size="10"> 낭만 캠핑</font></td>
        </tr>
 
        <tr height="50">
            <td width="110" align="center">텐트</td>
            <td width="110" align="center">의자</td>
            <td width="110" align="center">식기류</td>
            <td width="110" align="center">침낭</td>
            <td width="110" align="center">테이블</td>
            <td width="110" align="center">화롯대</td>
            <td width="110" align="center"><%=request.getParameter("id"%>
        </tr>
    </table>
</body>
</html>
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<%@ 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>
<body>
    <table width="200">
 
        <tr height="60">
            <td width="200" align="center"><a href="#"> 스노우 피크</a></td>
            <!-- 아무것도 실행하지는 않지만 페이지 최상단으로 이동한다. -->
        <tr height="60">
            <td width="200" align="center"><a href="#"> 콜맨</a></td>
        <tr height="60">
            <td width="200" align="center"><a href="#"> 지프</a></td>
        <tr height="60">
            <td width="200" align="center"><a href="#"> 코베아</a></td>
    </table>
</body>
</html>
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@ 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>
<body>
    <div style="text-align: center;">
        <table width="800">
            <tr height="100">
                <td align="center">이용약관 개인정보취급방침 이메일집단수집거부 경기도 부천시 오정구 삼정동
                    202-3 TEL: 032) 672-4501~4 FAX: 032) 672-0548 E-MAIL:
                    cs@batec.co.kr<br> 사업자등록번호: 130-81-68300 대표: 박광필
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
cs






-forward 예제 및 출력 결과-


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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
    <center>
        <form action="ResponseProc.jsp" method="post">
            <!-- post방식으로 자료를 보내면 암호화가 되지만 자료를 받는 jsp 파일에서 문자셋을 다시 셋팅해줘야한다. -->
            <table width="400" border="1">
 
                <tr height="50">
                    <td align="center" width="150">아이디</td>
                    <td width="250"><input type="text" name="id"></td>
                </tr>
 
                <tr height="50">
                    <td align="center" width="150">패스워드</td>
                    <td width="250"><input type="password" name="pass"></td>
                </tr>
 
                <tr height="50">
                    <td align="center" colspan="2"><input type="submit"
                        value="로그인"> &nbsp;&nbsp; <input type="reset" value="취소">
                    </td>
 
                </tr>
            </table>
        </form>
    </center>
</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=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
 
 
    <h2>이 페이지는 로그인 정보가 넘어오는 페이지 입니다.</h2>
 
    <%
        request.setCharacterEncoding("EUC-KR"); //post 방식 한글 처리
 
        String id = request.getParameter("id"); // request 객체 담겨진 사용자 정보중 id만 추출
 
        //response.sendRedirect("ResponseRedirect.jsp"); // ResponseRedirect.jsp로 자료를 넘겨준다. (하지만 request 안에 있는 값은 넘어가지 못한다.)(하지만 이렇게도 넘길수 있음 response.sendRedirect("ResponseRedirect.jsp?id="+id);)
    %>
    <!-- forward로 흐름제어를 하게 되면 request에 있는 내용이 그대로 살아서 ResponseRedirect.jsp 파일 까지 넘어가게 된다.-->
    <!-- request로 받아온 값을 변경을 하거나  유지시키고 싶을때  forward를 사용-->
    <!-- 밑에서 입력한 아이디의 값을 forward를 사용해서  'mmmm'으로 변경해 출력하고 있다.-->
    <jsp:forward page="ResponseRedirect.jsp">
        <jsp:param name="id" value="mmmm" />
    </jsp:forward>
    <!-- 흐름제어 -->
 
 
 
    <h3>
        아이디는<%=id%></h3>
    <!-- response.sendRedirect() 메소드를 사용해 자료를 넘겨주었기 때문에 실행되지 않는다. -->
 
 
</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
<%@ 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>
<body>
 
    <h2>ResponseRedirect.jsp 페이지 입니다.</h2>
 
    <%
        request.setCharacterEncoding("EUC-KR");
 
        String id = request.getParameter("id");
 
        String phone = request.getParameter("phone");
    %>
 
    <h3>
        아이디는<%=id%></h3>
    <h3>
        phone<%=phone%></h3>
 
</body>
</html>
cs



 

 

-자바빈즈-

 

여러개의 자바빈의 패키지 개념
여러개의 데이터를 하나의 클래스에 저장을 시켜놓고
그 클래스를 어레이리스트,배열 등에 저장해서 쓸때 자바빈즈라는 말을 쓴다.
jsp와 데이터베이스 간에 자료저장과 출력을 쉽게하기위한 것을 자바빈즈라고 한다.
각각 데이터를 넘기는 것보다 클래스로 만들어 넘기는 것이 훨씬 쉽고 효율적이기 때문에 사용한다.

 

 


-유즈빈-

 

데이터베이스에 있는 자료들이 자동으로 java파일에 저장된다.
빈을 사용하는 패턴

 

 


-자바빈-

 

자바로 만들어진 클래스
빈은 데이터베이스와 자바간에 데이터를 주고 받을때 많이 사용한다.
각각 데이터를 넘기는 것보다 클래스로 만들어 넘기는 것이 훨씬 쉽고 효율적이기 때문에 사용한다.

 

 

-예제 및 출력결과-

 

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=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
    <center>
        <h2>회원 가입</h2>
        <form action="MemberJoinProc.jsp" method="post">
            <table width="500" border="1">
                <tr height="50">
                    <td width="150" align="center">아이디</td>
                    <td width="350" align="center"><input type="text" name="id"
                        size="40" placeholder="id를 넣으세요"></td>
                </tr>
 
                <tr height="50">
                    <td width="150" align="center">패스워드</td>
                    <td width="350" align="center"><input type="password"
                        name="pass1" size="40" placeholder="비밀번호는 영문과 숫자만 넣어주세요">
                    </td>
                </tr>
 
                <tr height="50">
                    <td width="150" align="center">이메일</td>
                    <td width="350" align="center"><input type="email"
                        name="email" size="40"></td>
                </tr>
 
                <tr height="50">
                    <td width="150" align="center">전화번호</td>
                    <td width="350" align="center"><input type="tel" name="tel"
                        size="40"></td>
                </tr>
 
                <tr height="50">
                    <td width="150" align="center">주소</td>
                    <td width="350" align="center"><input type="text"
                        name="address" size="40"></td>
                </tr>
 
                <tr height="50">
                    <td align="center" colspan="2"><input type="submit"
                        value="회원가입"></td>
            </table>
        </form>
    </center>
</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=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
 
    <center>
        <h2>회원 정보 보기</h2>
        <%
            request.setCharacterEncoding("EUC-KR");
        %>
 
        <!-- request로 넘어온 데이터를 자바 빈즈랑 맵핑 시켜주는 useBean -->
        <!-- 여러개의 자료를 저장해놨다가 한번에 출력할수 있기 때문에 사용한다. -->
        <jsp:useBean id="mbean" class="bean.MemberBean">
            <!-- 객체 생성 MemberBean mbean = new MemberBean() -->
            <!-- Jsp 내용을  자바빈 클래스(MemberBean 의미)에 데이터를 맵핑(넣어줌)-->
            <jsp:setProperty name="mbean" property="*" />
            <!-- property 의 값을 *을 주면 모든 데이터를 맵핑시킬수있다. -->
 
        </jsp:useBean>
 
        <h2>
            당신의 아이디는
            <jsp:getProperty property="id" name="mbean" /></h2>
        <h2>
            당신의 패스워드는
            <jsp:getProperty property="pass1" name="mbean" /></h2>
        <h2>
            당신의 이메일은
            <jsp:getProperty property="email" name="mbean" /></h2>
 
        <h2>
            당신의 전화번호
            <%=mbean.getTel()%>
        </h2>
        <!-- 위쪽에서 이미 mbean의 객체를 생성해 놓았기 때문에 메소드를 호출할수 있다. -->
 
 
    </center>
</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
package bean;
 
public class MemberBean {
 
    private String id; // jsp파일에 있는 데이터와 1대1로 매핑시켜줘야 된다. 그래야 자료가 넘어오기 때문
    private String pass1;
    private String email;
    private String tel;
    private String address;
 
    public String getId() {
        return id;
    }
 
    public void setId(String id) {
        this.id = id;
    }
 
    public String getPass1() {
        return pass1;
    }
 
    public void setPass1(String pass1) {
        this.pass1 = pass1;
    }
 
    public String getEmail() {
        return email;
    }
 
    public void setEmail(String email) {
        this.email = email;
    }
 
    public String getTel() {
        return tel;
    }
 
    public void setTel(String tel) {
        this.tel = tel;
    }
 
    public String getAddress() {
        return address;
    }
 
    public void setAddress(String address) {
        this.address = address;
    }
 
}
 
cs

 

 

728x90
반응형
: