On Mon, 27 Aug 2001, Laurens Fridael wrote:
> Date: Mon, 27 Aug 2001 08:58:35 +0200
> From: Laurens Fridael <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: Tomcat mailing list <[EMAIL PROTECTED]>
> Subject: Tomcat 4, making "java:comp/env" writable
>
> Hi,
>
>
> Is there a way to make the "java:comp/env" JNDI context (and its
> subcontexts) writable in a release build of Tomcat 4? When I attempt to bind
> an object I get a "read-only" exception.
>
That would take some changes to the existing software (which deliberately
makes this namespace read-only). More importantly, it would create risks,
because it would let applications accidentally or maliciously scribble on
configuration settings.
> I have a servlet which runs at startup and makes some objects available via
> JNDI for later use. I *can* write to the root context (InitialContext) and
> retrieving objects stored there works fine. However, I strive to make my
> servlets and other classes as portable as possible. Resin (which I use for
> development but not deployment) only allows writing to the "java:comp/env"
> context.
>
> So I want to store objects in "java:comp/env" and below. In order for that
> to happen the context must be writable. Can anyone tell me if that is
> possible?
>
The portable way to make application objects available inside a web app is
to use servlet context attributes (also known as application scope beans
in JSP). In a servlet:
MyObject bean = ...
getServletContext().setAttribute("public", bean);
and this object is now available to all servlets and JSP pages in your web
application, under key "public".
>
> Regards
> -Laurens
>
>
>
Craig