src\tld(package)\Gugudan.java 파일 생성
package tld;
public class Gugudan {
public static String getGugu(String dan){
String gugu = "";
int d = Integer.parseInt(dan);
for(int i=1;i<=9;i++){
gugu += d + "x" + i + "=" + d*i + "<br>";
}
return gugu;
}
}
WEB-INF\tlds\tld-func.tld 파일 생성 (jsp - java파일을 연결시켜주는 역할)
<?xml version="1.0" encoding="euc-kr" ?>
<taglib version="2.0">
<tlib-version>1.0</tlib-version>
<function>
<description>구구단 출력</description>
<name>g</name>
<function-class>
tld.Gugudan
</function-class>
<function-signature>
java.lang.String getGugu(java.lang.String)
</function-signature>
</function>
</taglib>
-----------------------------j s p-------------------------------
<%@ page contentType="text/html; charset=EUC-KR" %>
<%@ page session="true" %>
<%@ taglib prefix="elfunc" uri="/WEB-INF/tlds/tld-func.tld" %>
${elfunc:g(param.dan)}
-----------------------------j s p-------------------------------
<%@ page contentType="text/html; charset=EUC-KR" %>
<%@ page session="true" %>
<%@ taglib prefix="elfunc" uri="/WEB-INF/tlds/tld-func.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:if test="${empty param.dan}">
숫자를 입력하세요.
</c:if>
<c:if test="${!empty param.dan}">
${elfunc:g(param.dan)}
</c:if>
-----------------------------j s p-------------------------------
<%@ page contentType="text/html; charset=EUC-KR" %>
<%@ page session="true" %>
<%@ taglib prefix="elfunc" uri="/WEB-INF/tlds/tld-func.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:choose>
<c:when test="${empty param.dan}">
숫자를 입력하세요.
</c:when>
<c:when test="${!empty param.dan}">
${elfunc:g(param.dan)}
</c:when>
<c:otherwise>음...</c:otherwise>
</c:choose>