当前位置: 代码迷 >> Java Web开发 >> 关于定制JSTL标签的有关问题
  详细解决方案

关于定制JSTL标签的有关问题

热度:90   发布时间:2016-04-17 13:59:59.0
关于定制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
                        {
                                  this.getBodyContent().getEnclosingWriter().print( "出错了! "+ " <br/> "+e);