package mypack;
import java.util.*;

public class Tool {
    public static int add(String x, String y) {
        int a = 0;
        int b = 0;
        try {
            a = Integer.parseInt(x);
            b = Integer.parseInt(y);
        }catch(Exception e) {}    
    
        return a + b;
    }

    public static String convert(String s,String encode1,String encode2){
        try{
            return new String(s.getBytes(encode1),encode2);
        }catch(Exception e){return null;}
     }
}
 
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib prefix="mm" uri="/mytaglib" %>
<html>
<head>
<title>functions</title>
</head>

<body>

<h3>Add Numbers</h3>
<p>
<form action="sum.jsp" method="get">
     user= <input type="text" name="user"    
                value="${mm:convert(param.user,'ISO-8859-1','GB2312')}">
     <br>
    
     x = <input type="text" name="x" value="${param.x}">
     <br>
     y = <input type="text" name="y" value="${param.y}">
     <input type="submit" value="Add Numbers">
</form>

<p>
the sum is: ${mm:add(param.x,param.y)}

</body>
</html>
mytaglib.tld
<?xml version="1.0" encoding="ISO-8859-1" ?>

<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.1</tlib-version>
        <short-name>mytaglib</short-name>
        <uri>/mytaglib</uri>
        

    <function>
        <description>add x and y</description>
        <name>add</name>
        <function-class>mypack.Tool </function-class>
        <function-signature>
             int add(java.lang.String,java.lang.String)
        </function-signature>
    </function>

    <function>
        <description>convert encoding</description>
        <name>convert</name>
        <function-class>mypack.Tool </function-class>
        <function-signature>
             java.lang.String convert(java.lang.String,java.lang.String,java.lang.String)
        </function-signature>
    </function>

</taglib>
web.xml
    
    <taglib>
            <taglib-uri>/mytaglib</taglib-uri>
            <taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
     </taglib>