선택장애

JSP - Forward_Action, response.sendRedirect 본문

JSP

JSP - Forward_Action, response.sendRedirect

yes or yes 2017. 8. 14. 14:50
반응형

Foward Action태그는 다른 페이지로 프로그램의 제어를 이동할 때 사용되는 액션 태그이다.
여기서는 총 3페이지를 만들어서 넘겨보겠습니다.


response.senRedirect태그는 한 페이지까지만 이동할 수 있는 태그이다.

/////////////////////////////////////////////////////////////////////////////////////////////////////
Forward1.jsp
/////////////////////////////////////////////////////////////////////////////////////////////////////

<%@ 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>Insert title here</title>
</head>
<body>
<form name="form1" action="Forward2.jsp" method="post">
//두번째 페이지인 Forward2로 넘기는 액션
<h2 align="center"> 테스트 폼11111</h2>
forward action : <input type ="text" name="name1"><input type="submit" name="button" value="확인"> <br><br>
</form>
<form method="form1" action=response_sendRedirect.jsp>
 response.sendRedirect : <input type="text" name="name2">
 <input type=submit value="확인">
</form>
</body>
</html>

////////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Forward2.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>
<% 
String name10 = request.getParameter("name1");

//name을 받을 객체 생성
String name11 = request.getParameter("name2");
%>
<body>
<jsp:forward page="Forward3.jsp">

//3페이지(Forward3)로 넘기기
 <jsp:param name="name1" value="<%=name10 %>"/>
 <jsp:param name="name2" value="000-000-0000"/>
</jsp:forward>

</body>
</html>


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Forward3.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>
<h2>Forward3 에서 Forward2 호출</h2>
<hr>
 Forward2 의 내용 출력
이름 : <%= request.getParameter("name1") %>
전화번호 : <%= request.getParameter("name2") %>
</body>
</html>

1페이지 > 2페이지 > 3페이지로 넘겨졌다.
1페이지에서는 보이는 부분
2페이지에서는 기능적인 제어기능
3페이지에서는 출력기능을 하였다.
(3페이지의 url을 보면 2페이지가 찍혀있다.)



반응형