ServletContextListener « API « JSP-Servlet Q&A

1. Throwing an exception from a ServletContextListener

I want to throw a ServletContext exception from a method in a class which implements ServletContextLister. Here is my implementation which is failing:

public class  Initializer implements ServletContextListener {


2. Use of variables in ServletContextListener

Is there any reason why a variable can't be created in a Java ServletContextListener and it's value set and get like any other. What I have is an ArrayList in an ...

3. Prefered way to handle Java exceptions in ServletContextListener

For servlet lifecycle stuff, what do you guys recommend doing in response to an exception... For example,

public class Foo implements ServletContextListener {

    public void contextInitialized(ServletContextEvent ...

4. What is the lifecycle for class that is registered as ServletContextListener

I know what ServletContextListener is and how to implement/register it in web.xml. But the question is the following. At the start of web application single instance of listener per javaVM is ...

5. Fuse ESB ServletContextListener?

I'm a newbie in OSGI world and trying to deploy a sample application using Fuse ESB. My current app exposes a SOAP based service which is bundled in a WAR file ...

6. What are the possible causes for ServletContextListener to not be called

I am studying a Java Server, and I came across a problem with ServletContextListener. I see that it is not called, so when I do and getAttribute it always return null, ...

7. ClassNotFoundException with ServletContextlistener

I get an exception whenever I try getting context parameter from we.XML into a ServletContextListener class, I am really having hard times understanding why It is not working, here's the exception in ...

8. ServletContextListener

10. ServletContextListener Class fails

11. Cannot find ServletContextListener

12. Create ConnectionPool in ServletContextListener

import java.sql.Connection; import java.sql.SQLException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; public class DBConnection { public static Connection getDBConnection() throws SQLException { Connection conn = null; try { InitialContext ctx = new InitialContext(); DataSource ds = ( DataSource ) ctx.lookup( "java:comp/env/jdbc/MySQLDB" ); try { conn = ds.getConnection(); } catch( SQLException e ) { System.out.println( "Open connection failure: " + e.getMessage() ); } ...

13. ServletContextListener

14. ServletContextListener Question

15. ServletContextListener

16. Using ServletContextListener

I have a co-worker that would like to run a process when his web application is brought online (assuming periodic app server reboots). Every time his web app is brought up, he wants to spawn some other process. Would it be possible to use a ServletContextListener (and implement the contextInitialized method) to accomplish this? If I understand this correctly, this method ...

17. ServletContextListener

18. ServletContextListener???

heres a funny example i just thought of: you are production support for web application pointed to by it had some problems so you shut down the web application, while you debug it. but you gotta sleep. so you tell the sys ad, 'whatever you do, dont start the application, i am still fixing it' but you dont trust him, ...

22. about ServletContextListener

23. ServletContextListener & Threads

** To mods.. wasnt sure which forum to base this post.. Servlets/Threads etc please move it at your discretion.. ** Hi All, Having a brain strain. Heres what i'm trying to achieve, I wish to have a Class which listens to a socket and launches new socket threads for each connection... (this is ok) But I want the listening class (SocketListener) ...

24. Problem with ServletContextListener

25. ServletContextListener

26. using Global ServletContextListener in several modules in the webapp

There is nothing keeping you from instanciating all of your configuration objects from a single context listener. Having separate listeners is nice if you want the ability to add,remvoe, and reorder all of these actions without having to re-compile anything by simply editing your deployment descriptor. If you don't need this ability, by all means do everything from one listener.

27. Doubt in ServletContextListener, how it can be used for JDBC connection management?

Ewwww, bad idea! This code grabs a connection when the web application starts up, and releases it when the web application is shut down. Bad, bad idea. Hugely bad! Rather, you should use connection pooling -- preferably container-managed -- to obtain a connection when you need it, and to return it to the pool as quickly as possible. I wonder other ...

28. ServletContextListener

29. ServletContextListener doubt

32. ServletContextListener and jspInit

I'm using a context listener to instantiate an object and set it as an attribute of the context. In a jsp, I want to use the jspInit method to retrieve that object and hold it in a field for requests to use. (Using Tomcat 5.0, via Eclipse). But, the object is not there when jspInit runs. I printed the enumeration of ...

33. Regarding ServletContextListener

34. init method and ServletContextListener

35. servletcontextlistener

hi i have used servletcontext listener example code as follows, import javax.servlet.ServletContextListener; import javax.servlet.ServletContextEvent; import javax.servlet.*; import java.util.*; public class serv implements ServletContextListener { public ServletContext context=null; public void contextInitialized(ServletContextEvent ev) { try { context=ev.getServletContext(); context.setAttribute("a","a"); } catch(Exception e) { e.printStackTrace(); } } public void contextDestroyed(ServletContextEvent ev) { context=ev.getServletContext(); String s=context.getAttribute("a").toString(); System.out.println("as"+s); this.context=null; } } ###################### In web.xml i have mention ...

38. ServletContextListener not working

Hi everyone, I am trying to write a code to see a ContextListener class in action. I have a jsp, where clicking on a button will take me to a servlet. That servlet will retrieve a context attribute object and print it using out.println(). Also, the DD defines a context-param which is taken by the listener class and that parameter is ...

42. ServletContextListener