본문 바로가기
프로그래밍/jsp

[JSP2.3] 페이지 모듈화 와 요청흐름 제어 - 2

by 혀끄니 2024. 4. 3.
728x90

<jsp:forward>액션 태그를 이용한 JSP 페이지 이동

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
from
<jsp:forward page="/chap07/to/to.jsp"/>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
toto
</body>
</html>

-from.jsp 내용이 출력되지 않고 to.jsp만 출력되는 이유는 버퍼에 쌓여서 한번에 출력되기 때문에

바로 to.jsp가 출력되는 것이다.

 

<jsp:param>액션 태그를 이용해서 이동할 페이지에 파라미터 추가하기

<jsp:forward page="mo.jsp">
  <jsp:param name="first" value="BK">
  <jsp:param name="last" value="CHoi">
</jsp:forward>

 

기본 객체의 속성을 이용해서 값 전달하기

<%@ page contentType = "text/html; charset=utf-8" %>
<%@ page import = "java. util. Calendar" %>
<%
  Calendar cal= Calendar.getlnstance();
  request. setAttribute("time", cal);
%>
  <isp:forward page="/to/viewTime.jsp" I>
<%@page contentType = "text/html; charset=utf-8" %>
<%@ page import= "java.util.Calendar" %>
<html>
<head> <title> 현재 시간 <title><head>
<body>
<%
   Calendar cal = (Calendar) request.getAttribute("time");
%>
 현재 시간은 <%= cal.get(Calendar.HOUR) %>시
 <%= cal.get(Calendar.MINUTE)%〉분
 <%= cal.get(Calendar.SECOND)%〉초 입니다.
 </body>
</html>
728x90

'프로그래밍 > jsp' 카테고리의 다른 글

[JSP2.3] Cookie  (0) 2024.04.15
[JSP2.3] 자바빈과 <jsp:useBean>액션  (0) 2024.04.04
[JSP2.3] 페이지 모듈화 와 요청흐름 제어 - 1  (0) 2024.02.26
[JSP 2.3] 에러처리  (0) 2024.02.23
[JSP 2.3] 웹프로그래밍 - 2  (0) 2024.02.22