logobodytag.java

来自「介绍了j2ee开发常用的学习知识,如servlet,javamail,EJB等知」· Java 代码 · 共 61 行

JAVA
61
字号
package com.tag;

/**
 *
 * @author hyl
 */
import javax.servlet.http.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.*;
public class LogoBodyTag extends BodyTagSupport {
    //自定义标记属性
    private String heading = null;
    private String image =null;
    private String width =null;
    private String height =null;
    public int doStartTag( ) throws JspException{
        try {
            int h = new Integer(heading).intValue( );
            if(! (h > 0 && h < 7))
                throw new JspException(
                        "The 'heading' attribute value must between 1 and 6 inclusive.");
            
        } catch (JspException e) { throw new JspException(e.getMessage( )); }
        return EVAL_BODY_BUFFERED;
    }
    public int doEndTag( ) throws JspException {
        JspWriter out = pageContext.getOut();
        String imgDir = ((HttpServletRequest) pageContext.getRequest( )).getContextPath( )+"\\" ;
        // 获取体内容
        String message = getBodyContent( ).getString( ).trim( );
        try{
            //输出体内容
            out.println("<img src=\""+ imgDir + image + "\" width=\"" + width +
                    "\" height=\"" + height + "\" align=\"left\">" + "<H" + heading + ">" +message.toUpperCase() + "</H" + heading+ ">");
        } catch (java.io.IOException io) {}
        return EVAL_PAGE;
    } //doEndTag
    //methods designed to set attribute values
    public void setHeading(String level){
        this.heading= level;
    }
    public void setImage(String name){
        this.image = name;
    }
    public void setWidth(String width){
        this.width = width;
    }
    public void setHeight(String height){
        this.height = height;
    }
    //清空变量,避免标记重用产生问题
    public void release( ){
        heading = null;
        image =null;
        width =null;
        height =null;
    }// release
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?