zoukankan      html  css  js  c++  java
  • Struts2_day01--导入源文件_Struts2的执行过程_查看源代码

    导入源文件

    选中按ctrl + shift + t进入

    Struts2执行过程

    画图分析过程

     过滤器在服务器启动时创建,servlet在第一次访问时创建

    查看源代码

    public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter {
        protected PrepareOperations prepare;
        protected ExecuteOperations execute;
        protected List<Pattern> excludedPatterns = null;
        public void init(FilterConfig filterConfig) throws ServletException {
            InitOperations init = new InitOperations();
            Dispatcher dispatcher = null;
            try {
                FilterHostConfig config = new FilterHostConfig(filterConfig);
                init.initLogging(config);
                dispatcher = init.initDispatcher(config);
                init.initStaticContentLoader(config, dispatcher);
    
                prepare = new PrepareOperations(dispatcher);
                execute = new ExecuteOperations(dispatcher);
                this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);
    
                postInit(dispatcher, filterConfig);
            } finally {
                if (dispatcher != null) {
                    dispatcher.cleanUpAfterInit();
                }
                init.cleanup();
            }
        }
        /**
         * Callback for post initialization
         */
        protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
        }
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) res;
            try {
                if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
                    chain.doFilter(request, response);
                } else {
                    prepare.setEncodingAndLocale(request, response);
                    prepare.createActionContext(request, response);
                    prepare.assignDispatcherToThread();
                    request = prepare.wrapRequest(request);
                    ActionMapping mapping = prepare.findActionMapping(request, response, true);
                    if (mapping == null) {
                        boolean handled = execute.executeStaticResourceRequest(request, response);
                        if (!handled) {
                            chain.doFilter(request, response);
                        }
                    } else {
                        execute.executeAction(request, response, mapping);
                    }
                }
            } finally {
                prepare.cleanupRequest(request);
            }
        }
        public void destroy() {
            prepare.cleanupDispatcher();
        }
    }


    1 过滤器在服务器启动时候创建,创建过滤器时候执行init方法

    (1)在init方法中主要加载配置文件

    - 包含自己创建的配置文件和struts2自带配置文件

    ** struts.xml

    ** web.xml

  • 相关阅读:
    数据结构:数组、链表、栈、队列的理解
    JVM学习记录-JVM的内存结构管理和运行时数据区理解
    线程池ThreadPoolExecutor的一种扩展办法
    四级地址插件升级改造(京东商城地址选择插件)city-picker
    java8在Collection中新增加的方法removeIf
    使用lambda编程之延迟执行
    JSP的内置对象以及作用域。
    Netty 异步的、事件驱动的网络应用程序框架和工具
    Zookeeper 服务注册和发现
    Jetty 发布web服务
  • 原文地址:https://www.cnblogs.com/justdoitba/p/7867770.html
Copyright © 2011-2022 走看看