samedi 27 mai 2017

I can not figure out why ClassNotFoundException happened when i learn ServletContextListener

ClassNotFoundException

  1. platform:eclipse_ee_mars + tomcat8.5
  2. SimpleServletContext is mainly inspect the attributes.
  3. Here is my SimpleServletConetxtListenerCode

    package zhang.listenerandfilter;
    import java.util.Date;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextAttributeEvent;
    import javax.servlet.ServletContextAttributeListener;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    public abstract class SimpleServletContextListener 
    implements ServletContextListener , ServletContextAttributeListener{
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("Start Time:" + new Date());
    }
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("Stop Time:" + new Date());
    
    }
    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("Added an Attribute:" + scae.getName() + "=" + scae.getValue());
    }
    
    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("Removed an Attribute:" + scae.getName() + "=" + scae.getValue());
    }
    
    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        ServletContext sc = scae.getServletContext();
        System.out.println("Replaced an Attribute(Old):" + scae.getName() + "=" + scae.getValue());
        System.out.println("(New):" + scae.getName() + "=" + sc.getAttribute(scae.getName()));
    }
    
    

    }

here is my web.xml

<listener>
    <listener-class>zhang.listenerandfilter.SimpleServletContextlistener</listener-class>
</listener>

my project dirctory tree




Aucun commentaire:

Enregistrer un commentaire