Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have try your code example and it worked for me.</p> <pre><code> package app.classes; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; /** * Application Lifecycle Listener implementation class ContextListenerProcess * */ @WebListener public class ContextListenerProcess implements ServletContextListener { /** * Default constructor. */ public ContextListenerProcess() { // TODO Auto-generated constructor stub } public void contextDestroyed(ServletContextEvent sce) { } public void contextInitialized(ServletContextEvent sce) { // Do your startup work here System.out.println("Processing Started ....."); } } </code></pre> <p>and this is my web.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Use this definition if using a Java EE 6 container This also stops Eclipse from complaining that 3.0 is not a valid version &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt; --&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;listener&gt; &lt;listener-class&gt;app.classes.ContextListenerProcess&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;description&gt;&lt;/description&gt; &lt;display-name&gt;WebListenerServlet&lt;/display-name&gt; &lt;servlet-name&gt;WebListenerServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;app.classes.WebListenerServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;WebListenerServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/index.html&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>after i run the application with this configuration it was successful, i see the <code>Processing Started .....</code> message at the console when tomcat is started. I add only </p> <pre><code> &lt;dependency&gt; &lt;groupId&gt;javax.servlet&lt;/groupId&gt; &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt; &lt;version&gt;3.0.1&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>The difference between your code and mine is you put bracket after @WebListener annotation, you should delete it and your ContextListenerProcess class has no access modifier which means it is default, it should be public.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload