org.apache.struts.config.ForwardConfig浅析
struts-config.xml文件中每一个<froward>元素对应着一个org.apache.struts.config.ActionForward。ActionForward继承自ForwardConfig
<global-forward>元素用来声明全局的转发关系,它由零个或多个<forward>元素组成,<forward>元素用于把一个逻辑名影射到特定的URL,通过这种方式,Action类或者JSP文件无需指定实际的URL,只要指定逻辑名就能实现请求转发或者重定向。在<global-forwards>中定义的<forward>代表全局转发
<forward>元素中的className是指定和<forward>元素对应的配置类,默认值为org.apache.struts.action.ActionForward。
<forward>元素中的contextRelative项值为true,表示当path属性一"/"开头时,给出的是相对于当前上下文的URL。此项的默认值为false,它在org.apache.struts.config.forwardConfig中对应的属性为boolean contextRelative。
<forward>元素中的name是转发路径的逻辑名。此项是必须的,它在org.apache.struts.config.forwardConfig对应的属性为String name。
<forward>元素中的path指定转发或重定向的URI。此项是必须的,必须以"/"开头。当contextRelative属性为false时,表示URI路径相对于当前应用(application-relative);当contextRelative属性为true时,表示URI路径相对于当前上下文(context-relative),它在org.apache.struts.config.forwardConfig中对应的属性为String path。
<forward>元素中的redirect项为true时,表示执行重定向操作;当此项为false时,表示执行请求转发操作。此项默认为false。它在org.apache.struts.config.forwardConfig中对应的属性为boolean redirect。
以上<forward>元素中的各属性在forwardConfig中都有对应的get和set方法
类中方法解析
public class ForwardConfig implements Serializable {
public ForwardConfig() {
super();
}
public ForwardConfig(String name, String path, boolean redirect) {
super();
setName(name);
setPath(path);
setRedirect(redirect);
}
public ForwardConfig(String name, String path, boolean redirect,
boolean contextRelative) {
super();
setName(name);
setPath(path);
setRedirect(redirect);
setContextRelative(contextRelative);
}
public ForwardConfig(String name, String path, boolean redirect,
String module) {
super();
setName(name);
setPath(path);
setRedirect(redirect);
setModule(module);
}
protected boolean configured = false;
protected boolean contextRelative = false;
public boolean getContextRelative() {
return (this.contextRelative);
}
public void setContextRelative(boolean contextRelative) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.contextRelative = contextRelative;
}
protected String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.name = name;
}
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 module = null;
public String getModule() {
return (this.module);
}
public void setModule(String module) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.module = module;
}
protected boolean redirect = false;
public boolean getRedirect() {
return (this.redirect);
}
public void setRedirect(boolean redirect) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.redirect = redirect;
}
public void freeze() {
configured = true;
}
public String toString() {
StringBuffer sb = new StringBuffer("ForwardConfig[");
sb.append("name=");
sb.append(this.name);
sb.append(",path=");
sb.append(this.path);
sb.append(",redirect=");
sb.append(this.redirect);
sb.append(",contextRelative=");
sb.append(this.contextRelative);
sb.append(",module=");
sb.append(this.module);
sb.append("]");
return (sb.toString());
}
}