> -----Original Message-----
> From: A mailing list about Java Server Pages specification
> and reference
>
> I am developing JSP system that works with some persistent data on the
> server. I don't wont to fix the persistence mechanism - persistence
> engine should be easily replaced with another one (DBManager,
> FileManager, XMLManager) - and my problem is that I don't know how to
> implement the initialization / destruction of the Persistent Manager
> object
>
> the ideal solution would be
> // pseudo JSP page code
> <some code that will be invoked when new JSP object is initialized -
>   will initialize the PersistenceEngine or increment a counter>
> <some code that will be invoked when this JSP object is destroyed
>   will decrement the counter and destroy the PersistenceEngine if
>   counter == 0>
>
> ....
> normal code that handles JSP page request // we know that the
> persistence engine is initialized
> ...
>

Just think of JSPs as auto-generated servlets, which they are.
So presumably, therefore, you can override the init() method to do any one
time initialisation and destroy() to save/cleanup - just like you would in a
servlet.

You can store information, common to all requests, in objects outside of the
service method (ie Page scope) using the <%!  %> tags.

You can store information for each current user, for all requests in the
session object (session scope) - also available across pages/servlets.

If you want to store information common across a number of pages you can use
static objects within one of the pages/servlets (Application scope).

The bean mechanism in JSP makes things a little easier (in some ways) by
allowing you to create bean objects in which you can set the 'scope' - ie
request, page, session, application - without having to get your hands too
dirty. I always feel it helps to understand what's going on underneath the
bonnet (hood), personally :-)
You could make the constructor of your 'persistance', Page scope, bean read
a db for example and write out to the db in it's finalize() method.

Of course, beware of thread synchronisation issues whenever using objects
which have Page or Application (and potentially Session) scope.

> (I have working prototype with Servlets, but generating complex
> dynamic web pages from servlet is ... simple nightmare :(

I know what you mean :-)

HTH,

Steve

===========================================================================
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