config包之ExceptionConfig浅析

org.apache.status.config.ExceptionConfig浅析

struts-config.xml文件中每个<exception>元素都对应着一个org.apache.struts.config.ExceptionConfig对象
<global-exceptions>元素用于配置异常处理。它可以包含零个或者多个<exception>元素,在<global-exceptions>元素中定义的<exception>代表全局异常。
<exception>元素中的className属性是指定和<exception>元素对应的配置类,默认为org.apache.struts.config.ExceptionConfig
<exception>元素中的handler属性是指定异常处理类。默认为org.apache.struts.action.ExceptionHandler,它在org.apache.struts.config.ExceptionConfig中对应的属性为String handler.
<exception>元素中的key属性是指定在Resource Bundle中描述该异常的消息key,它在org.apache.struts.config.ExceptionConfig中对应的属性为String key.
<exception>元素中的path属性是指定当异常发生时的转发路径,它在org.apache.struts.config.ExceptionConfig中对应的属性为String path。
<exception>元素中的scope属性是指定ActionMessages实例的存放范围,可选值包括request和session。此项默认为request。它在org.apache.struts.config.ExceptionConfig中对应的属性为String scope。
<exception>元素中的type属性是指定所需处理的异常类的名字。此项是必须的,它在org.apache.struts.config.ExceptionConfig中对应的属性为String type。
<exception>元素中的bundle属性是指定Resource Bundle,它在org.apache.struts.config.ExceptionConfig中对应的属性为String bundle。

以上属性在org.apache.struts.config.ExceptionConfig中都有get和set方法

ExceptionConfig只有默认的构造函数,没有其他构造函数。

类中部分方法解析
public class ExceptionConfig implements Serializable {

    protected boolean configured = false;

    protected String bundle = null;

    public String getBundle() {
        return (this.bundle);
    }

    public void setBundle(String bundle) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.bundle = bundle;
    }

    protected String handler = "org.apache.struts.action.ExceptionHandler";

    public String getHandler() {
        return (this.handler);
    }

    public void setHandler(String handler) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.handler = handler;
    }

    protected String key = null;

    public String getKey() {
        return (this.key);
    }

    public void setKey(String key) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.key = key;
    }

    protected String path = null;

    public String getPath() {
        return (this.path);
    }

    public void setPath(String path) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.path = path;
    }

    protected String scope = "request";

    public String getScope() {
        return (this.scope);
    }

    public void setScope(String scope) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.scope = scope;
    }

    protected String type = null;

    public String getType() {
        return (this.type);
    }

    public void setType(String type) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.type = type;
    }

    public void freeze() {

        configured = true;

    }

    public String toString() {

        StringBuffer sb = new StringBuffer("ExceptionConfig[");
        sb.append("type=");
        sb.append(this.type);
        if (this.bundle != null) {
            sb.append(",bundle=");
            sb.append(this.bundle);
        }
        sb.append(",key=");
        sb.append(this.key);
        sb.append(",path=");
        sb.append(this.path);
        sb.append(",scope=");
        sb.append(this.scope);
        sb.append("]");
        return (sb.toString());

    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值