룽쓰의 개발도구

#JSTL의 redirect를 사용해보자 2 본문

CODE_ZIP/JSTL

#JSTL의 redirect를 사용해보자 2

디벨로퍼룽쓰 2021. 4. 20. 17:12

[ A. sendRedirect를 이용해보자 ]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:url var="next" value="divide.jsp">
	<c:param name="num1" value="100"/>
	<c:param name="num2" value="0"/>
</c:url>
<c:redirect url="${next }"></c:redirect>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

 

 

[ B. 보낸 값들의 오류 처리를 해보자 ]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>나눗셈 프로그램(313)</h3>

<c:catch var="ex">
<%
	int result = num1/num2;
	out.println("나눗셈의 결과는? "+result);
%>
</c:catch>
<c:if test="${ex != null }"> // 문제되는 내용이 있다는 것이다.<br>
익셉션이 발생했습니다.<br>
에러 메세지 :: ${ex.message }<br>
</c:if>

</body>
</html>

'CODE_ZIP > JSTL' 카테고리의 다른 글

#JSTL의 forTokens를 사용해보자  (0) 2021.04.20
#JSTL의 forEach를 사용해보자  (0) 2021.04.20
#JSTL의 redirect를 사용해보자  (0) 2021.04.20
#JSTL의 if와 switch 사용법  (0) 2021.04.20
#JSTL의 set랑 out을 사용해보자  (0) 2021.04.20