Programming Learning Diary

JSTL 사용 기본

페이지 정보

작성일 19-11-28 21:36

본문



사용하기전 해야할 사항.


여기에 있는 파일 2개를 

C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\examples\WEB-INF\lib 


764a9b247c5aff8ec9552ddf89709aff_1574943365_7124.png
 



C:\Program Files\Apache Software Foundation\Tomcat 8.5\lib

이곳에 넣어준다

764a9b247c5aff8ec9552ddf89709aff_1574943398_7589.png


 

1번 예제



jstl_01.jsp 파일 생성


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

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

<c:set var="num1" value="7"/>

<c:set var="num2" value="9"/>

<c:set var="result" value="${num1*num2}"/>

   

    

    

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

 ${num1}과 ${num2} 의 곲은 ${result}입니다.

 

</body>

</html>


-결과


764a9b247c5aff8ec9552ddf89709aff_1574943972_2399.png
 


2번예제


jstl_02.jsp 파일 생성




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

<%@ 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:set var="CODE" value="1111" scope="request"/>

<c:set var="PRODUCTNAME" value="온도습도계" scope="request"/>

<c:set var="PRICE" value="15,000" scope="request"/>

<jsp:forward page="jstl_03.jsp"/>

</body>

</html>



-jstl_03.jsp 파일 생성


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

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<h3>상품정보</h3>

상품코드:${CODE}<br>

상품명:${PRODUCTNAME }<br>

금액:${PRICE}<br>

</body>

</html>



-결과


764a9b247c5aff8ec9552ddf89709aff_1574945606_7862.png
 


3번예제 


-jstl_04.jsp 파일 생성


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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<form action="jstl_05.jsp">

숫자 1: <input name="num1">

숫자 2: <input name="num2">

<input type="submit" value="OK">

</form>

<body>

</body>

</html>


-jstl_05.jsp 파일 생성


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

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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>최대값 구하기</title>

</head>

<body>


<c:if test="${param.num1-param.num2>0}">

${param.num1}

</c:if>

<c:if test="${param.num1-param.num2<0}">

${param.num2}

</c:if>

</body>

</html>
 

-결과(1,3 입력)

764a9b247c5aff8ec9552ddf89709aff_1574947350_3863.png
 

4번예제 


-jstl_06.jsp 파일 생성


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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<form action="jstl_07.jsp">

(0,1,2)<input name="num1">

<input type="submit" value="OK">

</form>

</body>

</html>


-jstl_07.jsp 파일 생성


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

<%@ 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:choose>

<c:when test="${param.num1==0}">

처음 뵙겠습니다.

</c:when>

<c:when test="${param.num1==1}">

반갑 습니다.

</c:when>

<c:otherwise>

안녕하세요<br>

</c:otherwise>

</c:choose>

</body>

</html>


-결과(2입력)

764a9b247c5aff8ec9552ddf89709aff_1574947507_2196.png
 

5번예제 


-jstl_08.jsp 파일 생성


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

<%@ 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:forEach var="cnt" begin="1" end="5">

<font size="${cnt}">

대한민국

</font><br>

</c:forEach>

</body>

</html>


-결과

764a9b247c5aff8ec9552ddf89709aff_1574947577_9349.png

6번예제 


-jstl_09.jsp 파일 생성


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


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<%

String[] arr ={"불고기백반","오므라이스","김치찌개"};

request.setAttribute("MENU", arr);

%>

<jsp:forward page="jstl_10.jsp"/>

</body>

</html>


-jstl_10.jsp 파일 생성

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

<%@ 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>

<h3>점심 메뉴표</h3>

<ul>

<c:forEach var="dish" items="${MENU}">

<li>${dish}</li>

</c:forEach>

</ul>

</body>

</html>


-결과

764a9b247c5aff8ec9552ddf89709aff_1574947689_3336.png
 

7번예제 


-jstl_11.jsp 파일 생성


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

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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>동물의 왕국</title>

</head>

<body>

사자의 생일 잔치에 누가왔을까요?<br><br>

<c:set var="guests" value="토끼^거북이^사슴^곰"/>

<c:forTokens var="animal" items="${guests}" delims="^">

${animal }<br>

</c:forTokens>

</body>

</html>

-결과

764a9b247c5aff8ec9552ddf89709aff_1574947753_4844.png

첨부파일

댓글목록

등록된 댓글이 없습니다.