`
syjsky2011
  • 浏览: 12601 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

config包之ActionConfig浅析

 
阅读更多
ActionConfig浅析

struts-config.xml文件中每一个<action>元素对应着一个org.apache.struts.action.ActionMapping。ActionMapping继承自org.apache.struts.config.ActionConfig
<action-mappings>元素包含零个或多个<action>元素,<action>元素描述了从特定的请求路径到响应的Action类的影射,<action>元素中包含多个<exception>和<forward>子元素,它们分别配置局部的异常处理及请求转发仅当前的Action所访问。

<action>元素中的className是和<action>元素对应的配置元素。默认为org.apache.struts.action.ActionMapping。
<action>元素中的attribute是设置和Action关联的ActionForm Bean在request或session范围内的属性Key。如:Form Bean存在于request范围内,并且此项设为"myBean",那么request.getAttribute("myBean")就可以返回该Bean的实例。此项为可选,它在ActionConfig中对应的属性为String attribute。
<action>元素中的forward是指定转发的URL路径。它在ActionConfig中对应的属性为HashMap forward。
<action>元素中的include是指定包含的URL路径。它在ActionConfig中对应的属性为String include。
<action>元素中的input是指定包含输入表单的URL路径。当表单验证失败时,将把请求转发到该URL。它在ActionConfig中对应的属性为String input。
<action>元素中的name是指定和该Action关联的ActionForm Bean的名字。该名字必须在<form-bean>元素中定义过。此项是可选的。它在ActionConfig中对应的属性为String name。
<action>元素中的path是指定访问Action的路径,它以"/"开头,没有扩展名。它在ActionConfig中对应的属性为String path。
<action>元素中的parameter是指定Action的配置参数。在Action类的execute()方法中,可以调用ActionMapping对象的getParocessor()方法来读取该配置参数。它在ActionConfig中对应的属性为String parameter。
<action>元素中的roles是指定允许调用该Action的安全角色。多个角色之间以逗号隔开。在处理请求时,RequestProcessor会根据该配置项来决定用户是否有调用Action的权限。它在ActionConfig中对应的属性为String roles。
<action>元素中的scope是指定ActionForm Bean的存在范围,可选值为request和session。默认为session。它在ActionConfig中对应的属性为String scope。
<action>元素中的type是指定Action类的完整类名。它在ActionConfig中对应的属性为String type。
<action>元素中的unknown项为true,表示可以处理用户发出的所有无效的Action URL。默认为false。它在ActionConfig中对应的属性为boolean unknown。
<action>元素中的validate是指定是否要先调用ActionForm Bean的validate()方法。默认为true。它在ActionConfig中对应的属性为boolean validate。

ActionConfig类中的HashMap exceptions属性对应的是<action></action>包含的零个到多个<exception>元素的信息

ActionConfig类中方法解析
public class ActionConfig implements Serializable {

    protected boolean configured = false;

    protected HashMap exceptions = new HashMap();

    protected HashMap forwards = new HashMap();

    protected ModuleConfig moduleConfig = null;

    public ModuleConfig getModuleConfig() {
        return (this.moduleConfig);
    }

    public void setModuleConfig(ModuleConfig moduleConfig) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }

        this.moduleConfig = moduleConfig;
    }

    protected String attribute = null;

    public String getAttribute() {
        if (this.attribute == null) {
            return (this.name);
        } else {
            return (this.attribute);
        }
    }

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

    protected String forward = null;

    public String getForward() {
        return (this.forward);
    }

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

    protected String include = null;

    public String getInclude() {
        return (this.include);
    }

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

    protected String input = null;

    public String getInput() {
        return (this.input);
    }

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

    protected String multipartClass = null;

    public String getMultipartClass() {
        return (this.multipartClass);
    }

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

    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 parameter = null;

    public String getParameter() {
        return (this.parameter);
    }

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

    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 prefix = null;

    public String getPrefix() {
        return (this.prefix);
    }

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

    protected String roles = null;

    public String getRoles() {
        return (this.roles);
    }

    public void setRoles(String roles) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.roles = roles;
        if (roles == null) {
            roleNames = new String[0];
            return;
        }
        ArrayList list = new ArrayList();
        while (true) {
            int comma = roles.indexOf(',');
            if (comma < 0)
                break;
            list.add(roles.substring(0, comma).trim());
            roles = roles.substring(comma + 1);
        }
        roles = roles.trim();
        if (roles.length() > 0)
            list.add(roles);
        roleNames = (String[]) list.toArray(new String[list.size()]);
    }

    protected String[] roleNames = new String[0];

    public String[] getRoleNames() {
        return (this.roleNames);
    }

    protected String scope = "session";

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

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

    ////与用户请求的参数相匹配的后缀
    protected String suffix = null;

    public String getSuffix() {
        return (this.suffix);
    }

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

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


    protected boolean unknown = false;

    public boolean getUnknown() {
        return (this.unknown);
    }

    public void setUnknown(boolean unknown) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.unknown = unknown;
    }

    protected boolean validate = true;

    public boolean getValidate() {
        return (this.validate);
    }

    public void setValidate(boolean validate) {
        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        this.validate = validate;
    }

    //将<action></action>包含的<exception>元素的信息保存到HahsMap exceptions
    public void addExceptionConfig(ExceptionConfig config) {

        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        exceptions.put(config.getType(), config);

    }

    //将<action>元素下的forward信息全部保存到HashMap forwards中
    public void addForwardConfig(ForwardConfig config) {

        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        forwards.put(config.getName(), config);

    }

    //根据传入的key从excepions中检索一个ExceptionConfig对象
    public ExceptionConfig findExceptionConfig(String type) {

        return ((ExceptionConfig) exceptions.get(type));

    }

    //把exceptions中所有的Exceptionconfig对象全部取出放入一个ExceptionConfig数组中,并返回该数组
    public ExceptionConfig[] findExceptionConfigs() {

        ExceptionConfig results[] = new ExceptionConfig[exceptions.size()];
        return ((ExceptionConfig[]) exceptions.values().toArray(results));//

    }

    //检索ExceptionConfig对象
    public ExceptionConfig findException(Class type) {

        ExceptionConfig config = null;
        while (true) {

            //在本地检索ExceptionConfig对象
            String name = type.getName();//得到该对象对应实体类的名称
            config = findExceptionConfig(name);
            if (config != null) {
                return (config);
            }

            //在全局中检索ExceptionConfig对象
            config = getModuleConfig().findExceptionConfig(name);
            if (config != null) {
                return (config);
            }

            type = type.getSuperclass();//得到该对象对应实体类的父类的名称,再循环检索
            if (type == null) {
                break;
            }

        }
        return (null); // No handler has been configured

    }

    //根据<forward>元素中的name属性检索Forwardconfig对象
    public ForwardConfig findForwardConfig(String name) {

        return ((ForwardConfig) forwards.get(name));

    }

    //将HashMap forwards中的所有ForwardConfig对象全部保存到一个ForwardConfig数组中,并返回该ForwardConfig数组
    public ForwardConfig[] findForwardConfigs() {

        ForwardConfig results[] = new ForwardConfig[forwards.size()];
        return ((ForwardConfig[]) forwards.values().toArray(results));

    }

    public void freeze() {

        configured = true;

        ExceptionConfig[] econfigs = findExceptionConfigs();
        for (int i = 0; i < econfigs.length; i++) {
            econfigs[i].freeze();
        }

        ForwardConfig[] fconfigs = findForwardConfigs();
        for (int i = 0; i < fconfigs.length; i++) {
            fconfigs[i].freeze();
        }

    }

    //从exceptions中删除一个异常类的名字
    public void removeExceptionConfig(ExceptionConfig config) {

        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        exceptions.remove(config.getType());//config.getType()异常类的名字

    }


    /**
     * Remove the specified forward configuration instance.
     *
     * @param config ForwardConfig instance to be removed
     *
     * @exception IllegalStateException if this module configuration
     *  has been frozen
     */
    public void removeForwardConfig(ForwardConfig config) {

        if (configured) {
            throw new IllegalStateException("Configuration is frozen");
        }
        forwards.remove(config.getName());

    }

    public String toString() {

        StringBuffer sb = new StringBuffer("ActionConfig[");
        sb.append("path=");
        sb.append(path);
        if (attribute != null) {
            sb.append(",attribute=");
            sb.append(attribute);
        }
        if (forward != null) {
            sb.append(",forward=");
            sb.append(forward);
        }
        if (include != null) {
            sb.append(",include=");
            sb.append(include);
        }
        if (input != null) {
            sb.append(",input=");
            sb.append(input);
        }
        if (multipartClass != null) {
            sb.append(",multipartClass=");
            sb.append(multipartClass);
        }
        if (name != null) {
            sb.append(",name=");
            sb.append(name);
        }
        if (parameter != null) {
            sb.append(",parameter=");
            sb.append(parameter);
        }
        if (prefix != null) {
            sb.append(",prefix=");
            sb.append(prefix);
        }
        if (roles != null) {
            sb.append(",roles=");
            sb.append(roles);
        }
        if (scope != null) {
            sb.append(",scope=");
            sb.append(scope);
        }
        if (suffix != null) {
            sb.append(",suffix=");
            sb.append(suffix);
        }
        if (type != null) {
            sb.append(",type=");
            sb.append(type);
        }
        return (sb.toString());

    }
}

原文 http://blog.csdn.net/jason_z/article/details/1798059
分享到:
评论

相关推荐

    JAVA期末大作业课程设计基于SSH框架的管理系统.zip

    JAVA期末大作业课程设计基于SSH框架的管理系统。 基本原理 1. 相关技术 Structs 一、Structs1原理 ...控制器根据配置信息,对象ActionConfig将请求派发到具体的Action,对应的formBean一并传给这个

    Struts开发指南之工作流程

     ActionServlet是一个FrontController,它是一个标准的Servlet,它将request转发给RequestProcessor来处理, ActionMapping是ActionConfig的子类,实质上是对struts-config.xml的一个映射,从中可以取得所有的配置...

    根据nlp中互信息以及左右信息得到目标文件夹中的文本的重要短语,然后用solr建立索引

    配置类:eshore.cn.it.phrase.ActionConfig.java 里面可以配置需要建立提取关键短语的文本语料库等,请查看该类注释。 程序入口:eshore.cn.it.main IndexStart.java 在配置类中配置好参数之后,直接运行此程序,将...

    node-v10.22.0-darwin-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    基于JAVA的物流管理系统的源码设计与实现.zip

    毕业设计物流管理系统的设计与实现(Java版本) 采用Struts2+hibernate+Oracle10g+Tomcat 涉及车辆管理,配送点管理,运输方式管理,订单管理,员工管理,用户管理,部门管理,权限管理,角色管理等基础管理功能。

    基于VB+access实现的成绩分析统计系统(论文+源代码).zip

    基于VB+access实现的成绩分析统计系统(论文+源代码) 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。

    node-v10.14.2-linux-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    ASP+ACCESS网上购物系统设计(源代码+设计说明书+调研报告).zip

    ASP+ACCESS网上购物系统设计(源代码+设计说明书+调研报告).zip

    AO工艺设计计算(全).xls

    污水处理计算书

    node-v7.3.0-x86.msi

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    ASP+ACCESS在线考试系统设计(源代码+设计说明书).zip

    ASP+ACCESS在线考试系统设计(源代码+设计说明书).zip

    node-v11.10.0-linux-ppc64le.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip

    毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip 毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip 毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip毕业设计基于知识图谱和循环神经网络的推荐系统python源码+数据集.zip

    2024年老人机行业分析报告.pptx

    行业报告

    基于matlab实现的导线网平差,主要是附和导线平差程序,用于计算各点坐标并评定其精度 .rar

    基于matlab实现的导线网平差,主要是附和导线平差程序,用于计算各点坐标并评定其精度。.rar

    基于VB+access实现的学生学籍管理系统(系统+论文).zip

    基于VB+access实现的学生学籍管理系统(系统+论文) 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。

    ASP基于BS的工艺品展示系统的设计与实现(源代码+设计说明书).zip

    ASP基于BS的工艺品展示系统的设计与实现(源代码+设计说明书).zip

    经典SBR设计计算(全).xls

    污水处理计算书

    ASP+ACCESS网上花店毕业设计全套(设计说明书+源代码+说明).zip

    ASP+ACCESS网上花店毕业设计全套(设计说明书+源代码+说明).zip

    污水工艺设计计算书.xlsx

    污水处理计算书

Global site tag (gtag.js) - Google Analytics