You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2004/07/31 19:55:34 UTC

DO NOT REPLY [Bug 30424] - possible enhancement on bootup (or proving how little I know)...

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30424>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30424

possible enhancement on bootup (or proving how little I know)...

craig.mcclanahan@sun.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX



------- Additional Comments From craig.mcclanahan@sun.com  2004-07-31 17:55 -------
Unfortunately, this sort of solution has a technical flaw that makes it pretty
unattractive -- if someone puts struts.jar in a shared classpath in their
servlet container, then the static appInitParameters list is shared across *all*
applications, instead of being tied to one.  That is not a good thing.

If you really need access to configuration (or other) data in an environment
where the ServletContext is not available (where you could grab application
scope things), I would recommend you look at using JNDI resources.  In effect,
these act like static globals because you can reference them from anywhere, but
the container ensures that there is a unique set per application.  As an added
bonus, the actual configuration settings is set up externally from the WAR, so
you can do things like deploy the same WAR, unchanged, to a test machine and a
production machine that requires different settings.

Any J2EE container, and pretty much any useful standalone servlet container
today, includes support for JNDI, so the programming model is portable.  (For
standalone programs and unit tests, you can even grab a standalone JNDI
implementation from the Apache Directory Project in the incubator).  For Tomcat
in particular, see:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

For simple initialization parameters, the <env-entry> declaration is probably
what you want.  If you had such a parameter named "sessionTimeout" (and knew it
was an integer), this is the code required to access this variable:

    Context initContext = new InitialContext();
    Context context = (Context) initContext.lookup("java:comp/env");
    int sessionTimeout =
      ((Integer) context.lookup("sessionTimeout")).intValue();

Note that there are no references required to servlet API objects to do this.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org