JSTL/Servlet – JSTL <c:redirect> 커스텀 액션 사용하기
2016/01/30 - [프로그래밍/JSP/Servlet] - JSTL/Servlet – JSTL
다른 JSP 페이지를 호출하는 <jsp:forward> 표준 액션과 비슷한 커스텀 액션이 바로 <c:redirect> 커스텀 액션입니다.
<c:redirect uri="http://gakari.tistory.com" />
만약 다른 웹 자원을 호출하면서 데이터를 넘겨주어야 할 경우에는 <c:param> 이라는 커스텀 액션을 사용하면 됩니다.
<c:redirect uri="http://gakari.tistory.com" >
<c:param name="데이터 이름" value="데이터 값"/>
<c:param name="데이터 이름" value="데이터 값"/>
</c:redirect>
Redirect.jsp를 호출하면 Divide.jsp 페이지를 호출하는 예제를 만들어 봅시다.
Redirect.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>
<c:redirect url="Divide.jsp">
<c:param name="NUM1" value="5"/>
<c:param name="NUM2" value="0"/>
</c:redirect>
</body>
</html>
Divide.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String str1 = request.getParameter("NUM1");
String str2 = request.getParameter("NUM2");
int num1 = Integer.parseInt(str1);
int num2 = Integer.parseInt(str2);
%>
<!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>
<c:catch var="e"><!-- 일부러 divide by zero 에러를 발생 시킴 -->
<% int result = num1 / num2; %>
결과는? <%=result %>
</c:catch>
<c:if test="${e != null }" ><!-- 실제 출력되는지 확인 -->
에러 메시지 : ${e.message }
</c:if>
</body>
</html>
실행 화면
Divide.jsp 페이지가 정상적으로 호출되었고 파라미터도 잘 넘어간 것을 볼 수 있습니다.ㅈ
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet – JSTL <fmt:formatNumber> 커스텀 액션 사용하기 (0) | 2016.02.01 |
---|---|
JSTL/Servlet – JSTL <fmt:formatDate> 커스텀 액션 사용하기 (0) | 2016.01.31 |
JSP/Servlet – JSTL <c:out> 커스텀 액션 사용하기 (0) | 2016.01.31 |
JSP/Servlet – JSTL <c:url> 커스텀 액션 사용 하기 (1) | 2016.01.30 |
JSTL/Servlet – JSTL <c:catch> 커스텀 액션 사용 하기 (0) | 2016.01.30 |
JSP/Servlet – JSTL <c:forTokens> 커스텀 액션 사용하기 (0) | 2016.01.30 |
JSP/Servlet – JSTL <c:forEach> 커스텀 액션 사용하기 (0) | 2016.01.25 |
JSP/Servlet – JSTL <c:choose> 커스텀 액션 사용하기 (0) | 2016.01.25 |