getlocalnumbertag.java

来自「大家好啊 快来抢购J2ME东东 挺不错的啊 不要后悔啊 抓住机会」· Java 代码 · 共 69 行

JAVA
69
字号
package com.ora.jsp.tags.generic;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.ora.jsp.beans.locale.*;

/**
 * This class implements a custom action that inserts a numeric
 * value, formatted according to the currently selected locale,
 * in the response body.
 * It uses the com.ora.jsp.beans.locale.LocaleBean.
 *
 * @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
 * @version 1.0
 */
public class GetLocalNumberTag extends TagSupport {
    private String name;
    private double value;
    
    /**
     * Sets the LocaleBean name property.
     *
     * @param name the name of the LocaleBean
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * Sets the numeric value property.
     *
     * @param value the numeric value
     */
    public void setValue(double value) {
        this.value = value;
    }
    
    /**
     * Uses the LocaleBean, available in a scope as a variable
     * specified by the "name" property, to format the value 
     * specified by the "value" property. The result is added 
     * to the response body.
     */
    public int doEndTag() throws JspException {
        Object o = pageContext.findAttribute(name);
        if (o == null) {
            throw new JspException("LocaleBean named " + name + " not found");
        }
        if (!(o instanceof LocaleBean)) {
            throw new JspException("The object named " + name + 
                " is not a LocaleBean");
        }
        JspWriter out = pageContext.getOut();
        try {
            out.write(((LocaleBean) o).getNumberString(value));
        }
        catch (IOException e) {} // Ignore
        return EVAL_PAGE;
    }
    
    /**
     * Releases all instance variables.
     */
    public void release() {
        name = null;
        super.release();
    }
}

⌨️ 快捷键说明

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