728x90
반응형
1. Dispatcher방식 -> forward()
forward()[전달하기]는 클라이언트가 요청하면서 전송한 데이터를 그대로 유지한다.
RequestDispatcher dispatcher = request.getRequestDispatcher("dispatcher.jsp");
request.setAttribute("request","requestValue");
dispatcher.forward(request, response);
dispatcher.jsp
request 속성 값 : <%=request.getAttribute("request") %>
주소가 변경되지 않는다. (같은 request영역을 공유하게 됨)
객체 생성
RequestDispatcher dispatcher = request.getReuquestDispatcher(주소);
dispatcher.forward(request, response);
=> 내부의 request, response는 변경이 불가!!!
2. Redirect 방식 -> sendRedirect()
Redirect()[이동하기]는 새로운 페이지로 완전히 이동해서 기존 데이터를 하나도 사용할 수 없다.
<body>
<h4>JSP 내장객체 : response의 화면 이동 메소드</h4>
<%
response.sendRedirect("http://www.naver.com");
%>
<h6> 문서의 끝부분으로</h6>
</body>
response.sendRedirect("주소");
실행하게 되면 바로 네이버 화면으로 전환 된다
<h4>태크 글과 <h6>태그의 글은 출력이 안된것처럼 보인다.
하지만 <h4>태그는 출력되 됬었었고 화면 전환 후 뒤로 가기가 없기때문에 <h6>태그는 출력이 되지 않는다.
<h4>태그가 출력되자마자 화면 이동이 일어난것이기 때문에 출력이 안된것 처럼 보이는것.
728x90
반응형
'개발노트 > JSP_Servlet' 카테고리의 다른 글
[JSP] Action Tag (0) | 2021.04.22 |
---|---|
[JSP] JSP(JavaServerPages) (0) | 2021.04.21 |
[JSP] 값 전달 (0) | 2021.04.21 |
[JSP] application의 주요 메소드 (0) | 2021.04.21 |
[JSP] request 메소드 (0) | 2021.04.20 |