Servlet-ServletContextListener

来源:互联网 发布:java中list用法 编辑:程序博客网 时间:2024/06/10 12:12
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.

 *


 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 *
 *
 * This file incorporates work covered by the following copyright and
 * permission notice:
 *
 * Copyright 2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package javax.servlet;

import java.util.EventListener;

/**
 * Interface for receiving notification events about ServletContext

 * lifecycle changes.

 这个接口,可以接收到通知事件,这些通知事件是关于ServletContext的生命周期的变化的事件。

 *
 * <p>In order to receive these notification events, the implementation
 * class must be either declared in the deployment descriptor of the web
 * application, annotated with {@link javax.servlet.annotation.WebListener},
 * or registered via one of the addListener methods defined on

 * {@link ServletContext}.

为了接收到这些通知事件,这个实现类必须,要么在Web Application的部署描述中声明(web.xml就是这个部署描述),

要么通过WebListener注解进行注解,或者通过ServletContext的addListener进行注册。

 *
 * <p>Implementations of this interface are invoked at their
 * {@link #contextInitialized} method in the order in which they have been
 * declared, and at their {@link #contextDestroyed} method in reverse

 * order.

这个接口的实现(类)会按照它们声明的顺序依次被调用,在contextInitialized(环境初始化/上下文初始化),

并且会在contextDestroyed(环境毁坏/上下文毁坏)的时间按照它们声明的顺序的逆序被调用。

 *
 * @see ServletContextEvent
 *
 * @since Servlet 2.3
 */
public interface ServletContextListener extends EventListener {

    /**
     * Receives notification that the web application initialization

     * process is starting.

       web application初始化过程正在开始的时候会接收到通知

     *
     * <p>All ServletContextListeners are notified of context
     * initialization before any filters or servlets in the web

     * application are initialized.

      所有的ServletContextListeners(Servlet环境监听器)会优先得到context(环境/上下文)的初始化通知,

接收context(环境/上下文)的初始化的事件通知,要早于过web应用中的过滤器或者Servlet的初始化的通知。

     *
     * @param sce the ServletContextEvent containing the ServletContext

     * that is being initialized

      这个方法的入参是ServletContextEvent类型的,这个类里面包括一个正在被初始化的ServletContext(Servlet环境/Servlet上下文)。

     */
    public void contextInitialized(ServletContextEvent sce);

    /**
     * Receives notification that the ServletContext is about to be

     * shut down.

   接收通知,这个通知是ServletContext将要被关闭的通知。

     *
     * <p>All servlets and filters will have been destroyed before any

     * ServletContextListeners are notified of context

    所有的servlet和过滤器将会被毁掉,在任何ServeContextListeners(Servlet环境/上下文监听器)被通知之前。

     * destruction.
     *
     * @param sce the ServletContextEvent containing the ServletContext

     * that is being destroyed

      这个方法的入参是ServletContextEvent,它里面包含了那个正在将要被销毁的ServletContext(Servlet环境/上下文)

     */
    public void contextDestroyed(ServletContextEvent sce);
}



0 0