국비지원학원/JSP

98일차-JSP_JSTL_forTokens

초코맛 2019. 4. 3. 02:01
반응형
*forTokens
  • <c:forTokens>
  • for+StringTokenizer가 결합된 태그 
  • <%
  •     String data="값,,,,,"; //csv (컴마로 구분되는 값들)
  •     pageContext.setAttribute("data",data);
  • %>
  • <c:forTokens var="Token으로 구분된 문자열" 

<%@page import="day0313.TestVO"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    info="반복문 forEach 사용"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"  href="http://localhost:8080/jsp_prj/common/main_v190130.css"/>
<style type="text/css">
#wrap{margin:0px auto;width:800px; height:860px;}
#header{width:800px; height:140px; background:#FFFFFF  url(http://localhost:8080/jsp_prj/common/images/header_bg.png)  repeat-x;
           position: relative; }
#headerTitle{font-family: HY견고딕,고딕; font-size:35px;  font-weight:bold; text-align:center;
                /* padding-top: 35px */ position:absolute;  top:40px; left:290px; }
#container{width:800px; height:600px; }
#footer{width:800px; height:120px; }
#footerTitle{float: right; font-size:15px; padding-top:20px;  padding-right:20px; }
</style>
</head>
<body>
<div id="wrap">
     <div id="header">
           <div id="headerTitle">SIST Class4</div>
     </div>
     <div id="container">
     <select>
     <!-- 증가하는 값을 반복시킬 때 -->
           <c:forEach var="i" begin="1" end="100" step="1">
           <option value="${i}"><c:out value="${i}"/></option>
           </c:forEach>
     </select>
     <div>
     <%
     //배열의 값 출력
           String[] movie={"시네마 천국","주토피아","코어","7인의  사무라이","트루먼쇼","인셉션"};
           pageContext.setAttribute("movie", movie);
     %>
     <ul>
     <%-- <c:forEach var="i" begin="1" end="6" step="1"> --%>
     <c:forEach var="movie" items="${movie }">
     <c:set var="i" value="${i+1}"/>
           <li>${i})${movie}</li>
     </c:forEach>
     </ul>
     <%
     //List의 값 출력
           List<String> list=new ArrayList<String>();
           list.add("Java SE");
           list.add("Java EE");
           list.add("DBMS");
           list.add("HTML");
           pageContext.setAttribute("list", list);
     %>
     <ul>
     <c:forEach var="subject" items="${list}">
     <li><c:out value="${subject}"/></li>
     </c:forEach>
     </ul>
     
     <%
     //List가 Generic으로 VO를 가진 경우의 사용
     //forEach안에서 "변수명.getter명"
           List<TestVO> voList=new ArrayList<TestVO>();
         voList.add(new TestVO("정",3));
         voList.add(new TestVO("희",7));
         voList.add(new TestVO("재",6));
         voList.add(new TestVO("성",8));
         
         pageContext.setAttribute("vl", voList);
      %>
      <table>
      <thead>
      <tr>
         <th width="50">번호</th>
         <th width="100">이름</th>
         <th width="50">나이</th>
      </tr>
      </thead>
      <tbody>
      <c:forEach var="data" items="${vl}">
      <c:set var="cnt" value="${cnt+1}"/> <!--자동 초기화되어  0부터 들어감 -->
      <tr>
         <td><c:out value="${cnt}"/></td>
         <td><c:out value="${data.firstName}"/></td>
         <td><c:out value="${data.age}"/></td>
      </tr>
      </c:forEach>
      </tbody>
      </table>
     </div>
     </div>
     <div id="footer">
           <div id="footerTitle">copyright&copy; all right  reserved. class 4.</div>
     </div>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    info="for문과 StringTokenizer가 결합된 태그인 forTokens 사용"
    %>
    <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"  href="http://localhost:8080/jsp_prj/common/main_v190130.css"/>
<style type="text/css">
#wrap{margin:0px auto;width:800px; height:860px;}
#header{width:800px; height:140px; background:#FFFFFF  url(http://localhost:8080/jsp_prj/common/images/header_bg.png)  repeat-x;
           position: relative; }
#headerTitle{font-family: HY견고딕,고딕; font-size:35px;  font-weight:bold; text-align:center;
                /* padding-top: 35px */ position:absolute;  top:40px; left:290px; }
#container{width:800px; height:600px; }
#footer{width:800px; height:120px; }
#footerTitle{float: right; font-size:15px; padding-top:20px;  padding-right:20px; }
</style>
</head>
<body>
<div id="wrap">
     <div id="header">
           <div id="headerTitle">SIST Class4</div>
     </div>
     <div id="container">
     <%
           String  csvData="JavaSE,JavaEE,DBMS.Oracle,HTML5,JavaScript,CSS3,jQuery";
           pageContext.setAttribute("csv", csvData);
     %>
     <ul>
     <c:forTokens var="data" items="${csv}" delims=",.">
     <li><c:out value="${data}"/></li>
     
     </c:forTokens>
     </ul>
     </div>
     <div id="footer">
           <div id="footerTitle">copyright&copy; all right  reserved. class 4.</div>
     </div>
</div>
</body>
</html>

//간단하게 하고 2차 프로젝트 발표

반응형

'국비지원학원 > JSP' 카테고리의 다른 글

100일차-JSP_MultipartRequest,Summernote,Diary  (0) 2019.04.03
99일차-JSP_JSTL+다이어리  (0) 2019.04.03
97일차-JSP_JSTL(Jsp Standard Tag Library)  (0) 2019.04.03
96일차-JSP_액션태그  (0) 2019.03.31
95일차-JSP_내장 객체  (0) 2019.03.31