tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Wilson" <jnwil...@dallas.photronics.com>
Subject Re: Servlet static variable not accessible from init() ??
Date Mon, 17 Jan 2005 23:41:48 GMT
Thanks for responding. I modified the init() method of the servlet to 
redo everything that was being done in the contextInitialized() method 
to workaround the problem. The Listener was getting fired. A while after 
that NetBeans 'ran out of memory' so I restarted it. Now, after 
commenting out the workaround, I am unable to duplicate this problem. 
cblog is always set in the init() method now (like I was expecting). 
I'll leave the workaround code commented out just to see if my problem 
returns later. (Note to self: weird behaviour == restart IDE)

By "store in application scope" you mean: 
getServletContext().setAttribute(string, object) right??
This is then accessible via 
(object)getServletContext().getAttribute(string) and/or if the object 
had static fields set they would still be set and accessible via 
objectclassname.<i>public static string object.getSetting()</i>

Thanks again for responding,
    JW

QM wrote:

>On Mon, Jan 17, 2005 at 04:08:15PM -0600, Jonathan Wilson wrote:
>: I'm setting a servlets private static variable from within itself  via 
>: the contextInitialized(SCE) method but it's not accessible from the 
>: init() method once that get's called...I would have thought the static 
>: part would make that variable accessible to all thread of the servlet 
>: that was started...or is something else going on? Any help is appreciated.
>
>I didn't look all that closely for the bug itself, but this line caught
>my ele:
>
>: public class controller extends HttpServlet implements 
>: ServletContextListener {
>
>Any reason you're putting both in the same class?  You could have one
>ContextListener class instantiate a variable and store it in Application
>scope; then, the servlet could retrieve it in its init() method.  (Be
>sure to use the init( ServletConfig ) overload in that case.)
>
>Are you sure the ContextListener is being fired? (i.e. that it's been
>properly registered?)
>
>Another question: I don't have the JavaDoc in front of me, but does
>ContextListener (or any of its parent classes) have an init() method?
>
>-QM
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message