jsp <c:redirect> 태그

hoonak·2023년 6월 27일

지정된 jsp 페이지로 리다이렉트할 때 사용함. response.sendRedirect() 기능과 동일하며 c:redirect 태그로 리다이렉트할 때 매개변수를 전달할 수 있음.

형식

<c:redirect url = "redirect할 url">
	[<c:param name = "매개변수이름" value = "전달값 />]
    ...
</c:redirect>

여기서 url은 리다이렉트 될 url이 저장될 변수를 지정함.

예 1)

c:redirect 태그를 이용해 회원정보 출력창으로 리다이렉트함. 리다이렉트하면서 회원 정보를 매개변수로 전달함.

redirectTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    isELIgnored="false"
    import = 'java.util.*'
%>
<%@ taglib prefix = 'c' uri = 'http://java.sun.com/jsp/jstl/core' %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<!-- 리다이렉트할 페이지를 설정함. -->
	<c:redirect url = '/jstl/member1.jsp'>
		<!-- 리다이렉트할 페이지로 전달할 매개변수를 설정함. -->
		<c:param name = 'id' value = "${'hong' }" />
		<c:param name = 'pwd' value = "${'1234' }"/>
		<c:param name = 'name' value = "${'홍길동' }"/>
		<c:param name = 'email' value = "${'hong@test.com' }"/>
	</c:redirect>

</body>
</html>
profile
Hello World!

0개의 댓글