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());
}
}