12. 액션 태그
0. 목차
Chapter12. 액션 태그
Ch12 - 1. 액션 태그란?
Ch12 - 2. forward, include, param 태그 살펴보기
Ch12 - 1. 액션 태그란?
▶ 액션 태그란?
▷ JSP 페이지 내에서 어떤 동작을 하도록 지시하는 태그
- 페이지 이동, 페이지 include…
Ch12 - 2. forward, include, param 태그 살펴보기
▶ forward
▷ 현재의 페이지에서 다른 특정 페이지로 전환할 때 사용
// aaa.jsp로 이동
<jsp:forward page="aaa.jsp">
▶ 실습
▷ main.jsp 실행
<%@ 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>Insert title here</title>
</head>
<body>
<h1>main.jsp 페이지 입니다.</h1>
<jsp:forward page="sub.jsp" /> // sub.jsp로 forward 함 → main.jsp가 아닌 sub.jsp가 실행 됨
</body>
</html>
▷ sub.jsp가 실행 됨
▶ include
▷ 현재 페이지에 다른 페이지를 삽입할 때 사용
// include01.jsp >> 삽입 : include02.jsp >> 다시 컴백 include01.jsp
<jsp:include page="include02.jsp" flush="true" />
▶ 실습
▷ include01.jsp 실행
// include01.jsp
<%@ 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>Insert title here</title>
</head>
<body>
<h1> include01.jsp 페이지 입니다. </h1>
<jsp:include page="include02.jsp" flush="true" /> // include02.jsp를 삽입하려 함
<h1> 다시 include01.jsp 페이지 입니다. </h1>
</body>
</html>
// include02.jsp
...
<body>
<h1> include02.jsp 페이지 입니다. </h1>
</body>
...
▷ include02.jsp 삽입
// 소스 보기
// include01.jsp 실행
<!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>Insert title here</title>
</head>
<body>
<h1> include01.jsp 페이지 입니다. </h1>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
// include02.jsp 삽입
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<h1> include02.jsp 페이지 입니다. </h1>
</body>
</html>
// 다시 include01.jsp 실행
<h1> 다시 include01.jsp 페이지 입니다. </h1>
</body>
</html>
지시자 include를 사용해도 되지만 액션 태그로도 사용 가능
▶ param
▷ forward로 지정한 페이지로 갈 때 데이터도 함께 넣어서 보내는 태그
▷ 이름과 값으로 이루어짐
// forward_param.jsp로 페이지를 넘기는데 id와 pw도 함께 보내기
<jsp:forward page="forward_param.jsp">
<jsp:param name="id" value="abcdef" />
<jsp:param name="pw" value="1234" />
</jsp:forward>
▶ 실습
▷ forward.jsp 실행
// forward.jsp
<%@ 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>Insert title here</title>
</head>
<body>
<jsp:forward page="forward_param.jsp"> // forward_param.jsp로 갈 때
<jsp:param name="id" value="abcdef" /> // id도 가져가고
<jsp:param name="pw" value="1234" /> // pw도 가져가!
</jsp:forward>
</body>
</html>
// forward_param.jsp
// forward.jsp에서 보내면 받아 줄 코드 작성
...
<body>
<%!
String id, pw;
%>
<%
id = request.getParameter("id");
pw = request.getParameter("pw");
%>
<h1>forward_param.jsp 입니다.</h1>
아이디 : <%= id %><br />
비밀번호 : <%= pw %>
</body>
...
▷ forward_param.jsp가 실행 됨