본문 바로가기

[Java] ServletContextListener Test

java by 낼스 2014. 5. 7.
■ ServletContextListener Test
    ( http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/ )
    1. ServletContextListener Example
        1) Create a class and implement the ServletContextListener interface
            package com.mkyong;
            import javax.servlet.ServletContextEvent;
            import javax.servlet.ServletContextListener;

            public class AppServletContextListener implements ServletContextListener{

                @Override
                public void contextDestroyed(ServletContextEvent arg0) {
                    System.out.println("ServletContextListener destroyed");
                }

                @Override
                public void contextInitialized(ServletContextEvent arg0) {
                    System.out.println("ServletContextListener started");
                }
            }
    2) Put it in deployment descriptor ( web.xml )
        <web-app ...>
            <listener>
                <listener-class>com.mkyong.AppServletContextListener</listener-class>
            </listener>
        </web-app>


     3) restart tomcat server 


댓글