본문 바로가기

JSP(Java Server Page)/JSTL

JSTL when문

test3.jsp


<%@ page contentType="text/html; charset=UTF-8"%>

<%@ page trimDirectiveWhitespaces="true" %>

<%

   String cp = request.getContextPath();

%>

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>

<form action="test3_ok.jsp" method="post">

수 : <input type="text" name="num">

<input type="submit" value="결과">

</form>

</body>

</html>


========================================================================================

test3_ok.jsp


<%@ page contentType="text/html; charset=UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page trimDirectiveWhitespaces="true" %>


<%

   String cp = request.getContextPath();

request.setCharacterEncoding("utf-8");

%>


<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>


<c:choose>

<c:when test="${param.num%3==0 && param.num%2==0 }">

${param.num}은 2와 3의 배수입니다.

</c:when>

<c:when test="${ param.num%2==0 }">

${param.num}은 2와 3의 배수입니다.

</c:when>

<c:when test="${param.num%3==0 }">

${param.num}은 2와 3의 배수입니다.

</c:when>

<c:otherwise>

${param.num }은 2 또는 3의 배수가 아닙니다.

</c:otherwise>

</c:choose>

</body>

</html>



'JSP(Java Server Page) > JSTL' 카테고리의 다른 글

JSTL fmf  (0) 2013.07.02
JSTL import  (0) 2013.07.02
JSTL varStatus  (0) 2013.07.02
JSTL forEach문  (0) 2013.07.02
JSTL if문  (0) 2013.07.02