Questions tagged [servlet-listeners]

The servlet listener interfaces that define the methods to be invoked in response to a desired event.

The servlet listener interfaces that define the methods to be invoked in response to a desired event. You may need to take some action in response to specific events - such as starting and stopping the Web application. To receive messages the listener class must be configured in the deployment descriptor web.xml.

The following list of the listener interfaces:

  • ServletContextListener

    Implementing an interface ServletContextListener promotes change notifications to the servlet context web application which it is part.

  • ServletContextAttributeListener

    ServletContextAttributeListener interface can be used to receive messages about changes in the list of the attributes of the servlet context.

  • HttpSessionListener

    Implementing an interface HttpSessionListener promotes change notifications to the list of active sessions in a web applications.

  • HttpSessionAttributeListener

    We can store attributes in the HttpSession, then they will be available until the session ends. HttpSessionAttributeListener interface can be used to receive messages about session attribute lists changes in a web applications.

139 questions
77
votes
10 answers

Difference between Filter and Listener in Servlet (Java EE)

There are Filters and Listeners functionality in Servlet. I want to know exact difference between Filter and Listener.
kandarp
  • 4,619
  • 11
  • 31
  • 43
25
votes
3 answers

How to inject dependencies into HttpSessionListener, using Spring?

How to inject dependencies into HttpSessionListener, using Spring and without calls, like context.getBean("foo-bar") ?
19
votes
6 answers

ServletContextListener not being invoked

I creating a Java EE 7 project using Eclipse Maven plugin. My problem is when I run the application the class that implements SerlvetContextListener does not get invoked. What is causing this problem? @WebListener public class…
Mario Dennis
  • 2,766
  • 10
  • 28
  • 47
16
votes
1 answer

Multiple listeners in web.xml?

How do I specify multiple listener classes in web.xml? I tried searching the web without luck. I tried the following, but it seems that it doesn't work: org.obliquid.web.StartAndStop …
stivlo
  • 77,013
  • 31
  • 135
  • 193
10
votes
2 answers

How can I make a ServletContextListener stop the Java EE application?

I have a ServletContextListener which performs some database management functions when my Java EE application starts. This runs in my application before JPA and other pieces of the application are started/loaded. If the database maintenance fails I…
Freiheit
  • 7,407
  • 6
  • 52
  • 95
10
votes
1 answer

Why Spring Context not gracefully closed?

On stop or undeploy/redeploy of a Spring framework 3.0.5 based web application following error is logged in Tomcat7's catalina.out: SEVERE: The web application [/nomination##1.0-qa] created a ThreadLocal with key of type [java.lang.ThreadLocal]…
7
votes
1 answer

What is the difference between a Servlet Filter and a Servlet Context Listener?

What are the differences between using a Servlet Filter versus a Servlet Context Listener? When would you use one or the other?
BestPractices
  • 12,101
  • 27
  • 90
  • 134
7
votes
5 answers

contextDestroyed() vs addShutdownHook()

I'm currently implementing ServletContextListener and using contextDestroyed() to run cleanup tasks on my web application before it shuts down. However, I've been reading about how Runtime.addShutdownHook(Thread) can be used for the same…
Paul Bellora
  • 51,514
  • 17
  • 127
  • 176
6
votes
1 answer

Debug ServletContextListener.contextDestroyed() by setting the breaking point in eclipse

I implement a custom ServletContextListener and place the breakpoints on both the contextInitialized() and contextDestroyed(). When starting the web application using WTP , contextInitialized() can be stopped by the debugger. But when I shut down…
Ken Chan
  • 64,456
  • 22
  • 117
  • 138
6
votes
2 answers

Injecting dependencies to ServletContextListener with Guice

Since ServletContextListener is created by the server, not by Guice I can't find a way to make it work together. How do I get guice injector at ServletContextListener? Maybe there is better way to shutdown services like logger or persistance then…
6
votes
1 answer

InputStream left open from TimerTask call to Guava map; GlassFish complains on undeploy

I'm implementing ServletContextListener in order to schedule various jobs on my app server (GlassFish 3.1). I'm using contextInitialized() to schedule recurring tasks, and contextDestroyed() to call cleanup methods, such as shutting down…
Paul Bellora
  • 51,514
  • 17
  • 127
  • 176
6
votes
1 answer

servlet session , after logout , when back button of browser is pressed , again the secure page is shown

I have a servlet and a HTML page. How can I prevent the user from hitting the back button of the browser after logout? I have read the same question in stackoverflow , but the answers are using browser history disable with java script or using…
cc4re
  • 4,095
  • 3
  • 18
  • 27
5
votes
1 answer

How to register listener in Spring without deployment descriptor

I'm slowly stepping in Java world through Spring Framework (4.1.0) and need your help with Listeners. I have created application without deployment descriptor, all Spring related configuration is managed in @Configuration annotated classes.…
xyz
  • 2,197
  • 2
  • 23
  • 41
5
votes
2 answers

Starting the servlet when the application startup

I want to starting by fireing the servlet class before loading a jsp page, because i need to populate some data from the database in a jsp page. Servlet mapping in web.xml Index
IBRA
  • 1,035
  • 3
  • 20
  • 50
5
votes
2 answers

web.xml order or filter and listener

For a Java EE web application, I have a listener that implements ServletRequestListener, and a Filter. Is there a way to specify at web.xml that the filter should be called before the listener? I've already tried declaring the filter and its mapping…
David Portabella
  • 11,264
  • 22
  • 87
  • 164
1
2 3
9 10