package util;
public class MyMath {
public static int sum(int start, int end){
int sum = 0;
for(int cnt = start ; cnt <= end ; cnt++)
sum += cnt;
return sum;
}
}
그리고 math-functions.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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>math</short-name>
<function>
<name>squareroot</name>
<function-class>java.lang.Math</function-class>
<function-signature>doudle sqrt(double)</function-signature>
</function>
<function>
<name>total</name>
<function-class>util.MyMath</function-class>
<function-signature>int sum(int, int)</function-signature>
</function>
</taglib>
호출
호출 jsp페이지
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="m" uri="http://www.test.com/test/math-functions.tld" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>익스프레션 : 태그라이브러리(TLD) : 내가 만든 메서드 사용하기</title>
</head>
<body>
1부터 100까지의 합은?<br><br>
답 : ${m:total(1,100) }<br>
<br>
<!--
http://localhost/ElEx01/TldEx02_MyMethod.jsp?num1=1&num2=100
--------------------------
1부터 100까지의 합은?
답 : 5050
--------------------------
-->
${param.num1 }부터 ${param.num2 }까지의 합은?<br><br>
답 : ${m:total(param.num1, param.num2) }<br>
</body>
</html>
'JAVA > JSP & Servlet' 카테고리의 다른 글
표준 액션(standard action) : forward (0) | 2013.03.22 |
---|---|
표준 액션(standard action) : Include (0) | 2013.03.22 |
expression language 태그라이브러리(TLD) [자바의 정적 메서드 호출] -설정- (0) | 2013.03.21 |
익스프레션 언어(expression language) JavaBean 객체 (0) | 2013.03.21 |
익스프레션 언어(expression language) HashMap (0) | 2013.03.21 |