Hello all,
SS> Just think of JSPs as auto-generated servlets, which they are.
SS> So presumably, therefore, you can override the init() method to do any one
SS> time initialisation and destroy() to save/cleanup - just like you would in a
SS> servlet.
overriding init() and destroy is ok - I have only one question
'Is it standard (will it always work ?)' :)
(I suppose that all JSP from the same 'web application' share common
classloader ?)
>> -----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
>> ...
>>
SS> Just think of JSPs as auto-generated servlets, which they are.
SS> So presumably, therefore, you can override the init() method to do any one
SS> time initialisation and destroy() to save/cleanup - just like you would in a
SS> servlet.
SS> You can store information, common to all requests, in objects outside of the
SS> service method (ie Page scope) using the <%! %> tags.
SS> You can store information for each current user, for all requests in the
SS> session object (session scope) - also available across pages/servlets.
SS> If you want to store information common across a number of pages you can use
SS> static objects within one of the pages/servlets (Application scope).
SS> The bean mechanism in JSP makes things a little easier (in some ways) by
SS> allowing you to create bean objects in which you can set the 'scope' - ie
SS> request, page, session, application - without having to get your hands too
SS> dirty. I always feel it helps to understand what's going on underneath the
SS> bonnet (hood), personally :-)
SS> You could make the constructor of your 'persistance', Page scope, bean read
SS> a db for example and write out to the db in it's finalize() method.
SS> Of course, beware of thread synchronisation issues whenever using objects
SS> 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 :(
SS> I know what you mean :-)
SS> HTH,
SS> Steve
--
Best regards,
heyhey mailto:[EMAIL PROTECTED]
===========================================================================
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