config包之ForwardConfig浅析

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

    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值