日期:2014-05-18  浏览次数:20629 次

关于定制JSTL标签的问题
我第一次定制一个JSTL标签,并写了个JSP页面测试

首先写了一个JSTL标签处理器类:
package   com.iven.tag;

import   javax.servlet.jsp.tagext.*;
import   javax.servlet.jsp.*;

public   class   TempChangeTag   extends   BodyTagSupport
{
        protected   String   to= "Celsius ";

        public   void   setTo(String   to)
        {
                this.to=to;
        }
        public   String   getTo()
        {
                return   this.to;
        }

        public   int   doAfterBody()
        {
                try
                {
                        BodyContent   bc=this.getBodyContent();
                        JspWriter   out=bc.getEnclosingWriter();
                        String   bd=bc.getString();
                        String   fa=String.valueOf((Integer.parseInt(bd)+112));
                        String   ke=String.valueOf((Integer.parseInt(bd)+273));

                        if(to.equals( "Fahrenheit ")==true   ||   to.equals( "F ")==true)
                        {
                                out.print(fa);
                        }
                        else   if(to.equals( "Kelvin ")==true   ||   to.equals( "K ")==true)
                        {
                                out.print(ke);
                        }
                        else
                        {
                                out.print(bd);
                        }
                }
                catch(Exception   e)
                {
                        try