Mike Cannon-Brookes wrote:
>
> G'day guys,
>
> I have some business objects that need to be accessible to all of my JSP
> pages, and as such I can grab them from any of the JSP pages using
> <jsp:usebean ... scope="application"/>.
>
> My problem is, when the server starts up (I am using JRun on NT4 / IIS4) I
> need to create and setup these business objects. Basically I need to run a
> chunk of java code when the server starts.
>
> I could do this using a pre-loaded servlet - correct? Two questions:
>
> 1) After the objects have been setup, I don't need a servlet hanging around
> taking up memory. Is this approach inefficient?

That's a common way to handle it, and a small initialization servlet like
this will not use a whole lot of memory so it shouldn't be a problem.

> 2) How can I access the JSP application scope from a servlet? I have looked
> at the JRun generated .java files, but they seem to use a lot of
> properietary JRun methods to do this. Does anyone have a simple code snippet
> for this?

Application scope is the same as ServletContext attributes. So just use
ServletContext.setAttribute and the objects will be available to all
servlets and JSP pages in the same application.


--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to