1 / 15

JSP 9.1~9.3 JSTL 사용하기

JSP 9.1~9.3 JSTL 사용하기. 유 명 훈 ymh627@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술연구실 2012. 8. 23. 목차. JSTL 이란 ? JSTL 설치하기 코어 라이브러리 사용하기. JSTL 이란 ?(1/2). 간단한 프로그램 로직 구사 다른 JSP 페이지 호출 날짜 , 시간 , 숫자의 포맷 JSP 페이지 하나를 가지고 여러 가지 언어의 웹 페이지 생성 데이터베이스로 입력 , 수정 , 삭제 조회 XML 문서의 처리

kelly-hill
Download Presentation

JSP 9.1~9.3 JSTL 사용하기

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP9.1~9.3JSTL 사용하기 유 명 훈 ymh627@kunsan.ac.kr 군산대학교 통계컴퓨터과학과 정보과학기술연구실 2012. 8. 23

  2. 목차 JSTL이란? JSTL 설치하기 코어 라이브러리 사용하기 IST (Information Sciences & Technology) Laboratory

  3. JSTL이란?(1/2) 간단한 프로그램 로직 구사 다른 JSP페이지 호출 날짜, 시간, 숫자의 포맷 JSP 페이지 하나를 가지고 여러 가지 언어의 웹 페이지 생성 데이터베이스로 입력, 수정, 삭제 조회 XML 문서의 처리 문자열을 처리하는 함수 호출 커스텀 액션 형태 Xml 문법을 따르면서 특정한 동작 수행하는 태그 <c:forEach begin=“1” end = “10”> <H5>안녕하세요, 여러분!</H5> </c:forEach> <fmt:formatNumber value=“3.14159” pattern=“#.00” /> • JSP 표준 태그 라이브러리(JSP Standard Tag Library) • 커스텀 액션, 함수 제공 IST (Information Sciences & Technology) Laboratory

  4. JSTL이란?(2/2) ${fn:toUpperCase(“Hello”)} • JSTL-익스프레션언어에서 사용할 수 있는 EL함수 • c, fmt, fn접두어 • 커스텀 액션과 EL함수가 다른 라이브러리에 속하기 때문 • <%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %> IST (Information Sciences & Technology) Laboratory

  5. JSTL 설치하기 • JSTL 1.1 • jstl.jar • standard.jar • http://jakarta.apache.org/ IST (Information Sciences & Technology) Laboratory

  6. 코어 라이브러리 사용하기(1/9) intnum=100; 자바 프로그래밍 커스텀 액션 <c:setvar=“num” value=“100” /> <c:setvar=“num” value=“100” /> … ${num} <c:setvar=“num” value=“100” /> … <%= num %> page 영역의 애트리뷰트 이기 때문에 <c:setvar=“num” value=“${num1+num2}” /> <c:setvar=“num” value=“15000” scope=“request” /> • <c:set> 커스텀 액션 사용 방법 • 변수를 선언하고 나서 그 변수에 초기값을 대입하는 기능 • EL식 안에서 사용 • 익스프레션 안에서 사용x IST (Information Sciences & Technology) Laboratory

  7. 코어 라이브러리 사용하기(2/9) <c:removevar=“num” /> <c:setvar=“num” scope=“request” /> 익스프레션언어 EL 식 형태로 기술해야 함 if(num1 < num2){ System.out.println(“num1이 더 큼”); } <c:if test=“${num1 < num2}”> num1이 더 큼 </c:if> • <c:remove> 커스텀 액션 사용 방법 • <c:set> 커스텀 액션을 이용해서 선언한 변수를 삭제하는 방법 • <c:if> 커스텀 액션 사용 방법 • 주어진 조건에 따라 어떤 동작을 수행하도록 만드는 액션 IST (Information Sciences & Technology) Laboratory

  8. 코어 라이브러리 사용하기(3/9) switch(num){ case 0 : System.out.println(“2시간.”); break; case 1 : System.out.println(“12시간.”); break; default : System.out.println(“24시간.”); break; } <c:choose> <c:when test=“$num == 0” > 2시간. <BR> </c:when> <c:when test=“$num== 1” > 12시간. <BR> </c:when> <c:otherwise> 24시간. <BR> </c:otherwise> </c:choose> • <c:choose> 커스텀 액션 사용 방법 • switch,case, default -> <c:choose>, <c:when>, <c:otherwise> IST (Information Sciences & Technology) Laboratory

  9. 코어 라이브러리 사용하기(4/9) for(intcnt=0; cnt < 10; cnt++){ System.out.println(“47347200초”); } <c:forEach begin=“1” end = “10”> 47347200초 <BR> </c:forEach> <c:forEachvar=“cnt” begin=“1” end = “10”> ${cnt} <BR> </c:forEach> <c:forEachvar=“cnt” begin=“1” end = “10” step=“2”> ${cnt} <BR> </c:forEach> <c:forEachvar=“str” items=“${arr}” > ${str} <BR> </c:forEach> • <c:forEach> 커스텀 액션 사용 방법 • 일정 횟수만큼 반복 IST (Information Sciences & Technology) Laboratory

  10. 코어 라이브러리 사용하기(5/9) <c:forTokensvar=“icecream” itmes = “초코민트레인보우샤베트폴라베어요거트” delims=“ ”> ${icecream}<BR> </c:forTokens> <c:forTokensvar=“alcohol” itmes = “소주*맥주/막걸리-매실주” delims=“*/-”> ${alcohol}<BR> </c:forTokens> • <c:forTokens> 커스텀 액션 사용 방법 • 문자열에 포함된 토큰을 분리해서 각각의 토큰에 대해 반복 처리를 수행하는 기능 • for문 + java.util.StringTokenizer • items, delims, var IST (Information Sciences & Technology) Laboratory

  11. 코어 라이브러리 사용하기(6/9) try{ int result = num1 / num2; System.out.println(result); } catch(Exception e){ System.out.pirnln(e.getMessage()); } <c:catchvar=“e”> <% int result = num1/ num2 %> 나눗셈의 결과는? <%= result %> </c:catch> <c:if test=“${e != null}”> 에러 메시지 : $ {e.message} </c:if> • <c:catch> 커스텀 액션 사용 방법 • 자바의 try catch문과 비슷함 IST (Information Sciences & Technology) Laboratory

  12. 코어 라이브러리 사용하기(7/9) <c:redirecturl=“http://www.hanb.co.kr”/> <c:redirecturl=“http://www.hanb.co.kr/Buy.jsp”/> <c:param name=“code” value=“75485” /> <c:param name=“code” value=“2” /> </c:redirect> • <c:redirect> 커스텀 액션 사용 방법 • 다른 JSP페이지 호출 • sendRedirect메서드와 동일한 방법으로 작동 • JSP와 다른 웹 서버에 있는 웹 자원도 호출 가능 IST (Information Sciences & Technology) Laboratory

  13. 코어 라이브러리 사용하기(8/9) <c:importurl=“http://www.hanb.co.kr/binfo/BrainSeries.jsp”/> <c:importurl=“http://www.hanb.co.kr/AdScrap.jsp”> <c:param name=“product” value=“TV” /> <c:param name=“ad_index” value=“007” /> </c:import> <c:urlvar=“myUrl”value=“http://localhost:8080/barin09/add.jsp” > <c:urlvar=“myUrl”value=“http://localhost:8080/barin09/add.jsp” > <c:param name=“NUM1” value=“999” /> <c:paramname=“NUM2” value=“1” /> </c:url> • <c:import> 커스텀 액션 사용 방법 • 현재 JSP페이지에 다른 JSP페이지의 결과를 포함시키는 일 • <c:url> 커스텀 액션 사용 방법 • URL을 저장하기 위한 변수의 선언에 사용함 IST (Information Sciences & Technology) Laboratory

  14. 코어 라이브러리 사용하기(9/9) • <c:out> 커스텀 액션 사용 방법 • 데이터 출력 • <, >, &, ‘, “ 이스케이프 시퀀스로 변환 IST (Information Sciences & Technology) Laboratory

  15. 감사합니다유명훈ymh627@kunsan.ac.kr

More Related