actionTag.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
<%@ 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">
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
 
<!--
    [   액션 태그   ]
    1. forward 액션 태그
        : 현재 페이지에서 다른 페이지로 이동시킬 때 사용한다. 단! response.sendRedirect()와는 달리
            !! 페이지를 이동해도 URL이 바끼지 않고 페이지 이동 전 URL상태로 남아있게 되는게 특징이다.
            ex) A페이지에서 B페이지로 이동해도 주소창에는 A페이지 주소임
    2. include 액션 태그
        : include 지시자와 달리 동적으로 페이지에 소스코드를 붙여넣는 효과
        : forward와 include 액션 태그는 param 액션 태그를 통해 데이터를 전달할 수 있다.
    3. param 액션 태그
 -->
  
    <!-- 1. forward 액션 태그 -->
    <jsp:forward page="forward01.jsp">
        <!-- param을 통해 forward01.jsp로 age,name을 전달하고 있고, 해당 forward01.jsp에서는
            request.getParameter("age")등을 통해 데이터를 꺼내올 수 있다.
         -->
        <jsp:param value="28" name="age"/>
        <jsp:param value="이름" name="name"/>
    </jsp:forward>
     
    <!-- 2. include 액션 태그 -->
    <jsp:include page="include02.jsp" flush="false">
        <jsp:param value="seoul" name="local"/>
    </jsp:include>
     
    아래는 그대로 actionTag.jsp 페이지 내용이 바로 오게 된다.


forward01.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<%@ 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">
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
 
    <%
        String age = request.getParameter("age");
        int ages = Integer.parseInt(age);
        String name = request.getParameter("name");
    %>
    <%=name %> : <%=age %>


include02.jsp
1
2
3
4
5
6
7
8
9
10
11
<%@ 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">
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
 
    include02.jsp 페이지입니다.
    전달받은 값은 : <%=request.getParameter("local") %>입니다.



+ Recent posts