본문 바로가기

기타/기타

Jstl Customer Tag 사용법

Jstl Customer Tag 사용법

 

 

경로 : WEB-INF 바로 밑으로 생성 ( tld 파일 만 )

 

myFunction.tld

 

<?xml version="1.0" encoding="UTF-8"?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">

<tlib-version>1.2</tlib-version>
 <uri>DiceFunctions</uri>
 
   <!-- 그냥 일반 void 실행시 -->
     <function>
       <description>  
            함수용도 작성하는 곳
         </description>
         <name>rollIt</name>
         <function-class>com.example.DiceRoller</function-class>
         <function-signature>
             int rollDice()
         </function-signature>
         <example>
          ${mine:rollIt()}
         </example>
     </function>
     
     <!-- Parameter 를 이용한 함수 사용하기 -->
     <function>
      <description>

            함수용도 작성하는 곳

      </description>
      <name>testDance</name>
      <function-class>com.example.DiceRoller</function-class>
      <function-signature>
       String danceTest(java.lang.String, java.lang.String)
      </function-signature>
      <example>
       ${mine:testDance(seq,Id)}
      </example>
     </function>


 </taglib> 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



★ 설명 :
description - 서술 기술 설명


 

 

DiceRoller.java

package com.example;

 

public class DiceRoller {
    public static int rollDice() {
        return (int) ((Math.random() * 6) + 1);
    }
    
    public static String danceTest(String seq, String id){
     String result = "";
     result = seq+id;
     System.out.println(result);
     return result;
    }



 

 

 

 

 

 

 

 

 

 

 

 

 

★ Tip : Java 파일을 생성하고 static 로 잡아줘야 한다 이유는 좀더 찾아봐야함.. ㅠㅠ

 

 

 

Test.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="mine" uri="DiceFunctions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
<title>Jstl Tag 사용하기</title>
</head>

<body>
${mine:rollIt()}
<br/>
<br/>

${mine:testDance('fwspchj','Yahoo')}
</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

설명 : 3번쨰줄 taglib 사용 prefix mine 설정 uri은 해당 파일의 url 명을 입력한 것이다 !!

 

 

 

 

'기타 > 기타' 카테고리의 다른 글

공부할것들  (0) 2016.04.20
세션과 쿠키의 차이점  (0) 2015.01.07
asd  (0) 2014.12.17
[서블릿과 JSP] HttpServletRequest 인터페이스 상세설명  (0) 2014.11.03
아키텍트의 종류와 역할  (0) 2014.04.04