Ben Flynn
Ben Flynn

Reputation: 18922

Loading my ServletContextListener in Tomcat 7

New to Tomcat and running Tomcat 7 in an Eclipse environment.

I followed a tutorial for creating a ServletContextListener class. My question is, simply, how do I get this loaded and running in Tomcat? Can I use annotations? Do I need to edit an xml file?

Upvotes: 3

Views: 5568

Answers (3)

Pidster
Pidster

Reputation: 618

When you download Tomcat 7.0 from the Apache Tomcat website you'll get a version that includes an examples application. There is source code and configuration for some of the Servlet 3.0 features, like annotations.

Have a look at those examples - they're useful.

Upvotes: 0

Ryan Stewart
Ryan Stewart

Reputation: 128839

As an example in the web.xml:

<listener>
    <listener-class>fully qualified class name of your listener class</listener-class>
</listener>

Upvotes: 4

JB Nizet
JB Nizet

Reputation: 691755

Javadoc to the rescue:

In order to receive these notification events, the implementation class must be either declared in the deployment descriptor of the web application, annotated with WebListener, or registered via one of the addListener methods defined on ServletContext.

Upvotes: 4

Related Questions