Web/JSP
jsp액션태그 - forward, param, include
surhommejk
2017. 12. 3. 13:22
forward시에 url값은 변하지 않는다!!
실습예제)
t01에서 t02로 param을 보낸다
t02에서 t01의 param을 받아서 출력 + include로 t03의 내용을 출력
t01
<%@ 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="t02.jsp">
<jsp:param name = "id" value = "surhomme" />
<jsp:param name = "pw" value = "12345" />
</jsp:forward>
</body>
</html>
cf) jsp:forward 구문이 시작되어도 ' / ' <--를 만나기 전까지는 페이지 이동이 실행되지 않는다고 보는 것이 이해하기 좋다. 그러니 /jsp:forward 사이에 있는 정보들이 전송되는 것이다.
t02
<%@ 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:include page="t03.jsp" />
t02 페이지 입니다 <br/>
t01 에서 받은 id와 비밀번호는 <br/>
<%
String id = request.getParameter("id");
String pw = request.getParameter("pw");
out.println(id + "<br/>");
out.println(pw);
%>
</body>
</html>
t03
<%@ 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>
t03 페이지 입니다 <br/>
</body>
</html>