Hi,
Actually I would like to clarify my requirement. The screens are related to e-com
selection criteria. There are so many combobox in any of those screens for which
the data needs to be fetched from the database. But the same data can be reused in
other screens too. For example if I need country list for selection in one of the
screen, the same list is used for selection in other screens too. But these screens
may be related or may not be. So what I want, the first time I need the country
list, I will be fetching those details from the data base and will store in a bean
to avoid the traffic to the database. For subsequent requests, the list will be
fetched from the bean only. Similarly whenever any other list is needed, it will be
fetched from the database and will be stored in the same bean.
Now I want to create only one instance of the bean throughout the session which
could be reused in other screens too. That's why I thought of using Singleton
pattern. But at present I am not clear, whether the bean instance which is being
created in one of the JSP could be used in other JSPs too, ie if Singleton instance
is created in one of the screen, it should not be created in subsequent screens.
Please suggest.
-ShriKant
Rathna wrote:
> hi shri,
>
> The bean Object access scope will be limited to the page
> where it has been instantiated regardless of the bean scope.
>
> But when you instantiate the object in the subsequent page
> the creation of the object will be decided upon the scope
> of the object.for example you are trying to create the object
> again which is in the scope 'session' then you will get the
> same reference.
>
> In case of singleton ,provide a static method to get the
> object of the class and have the implementation as follows,
>
> create the object of it's own when it does not exists in
> the JVM and return the reference.Make sure you are having
> the constructor as private.
>
> Then call the static method of the class to get the reference
> instead of using usebean tag.
>
> hope this helps,
>
> with regards,
> rathna.
>
> >>Hi,
>
> I have a requirement where I have to store the data in a persistent java
> class and then whenever user requires it he can use it. So per session I
> want to create only one instance of the class which will be used in
> different JSPs.
>
> I want to use Singleton pattern to maintain only one instance per
> session. So in any JSP if user wants to create another instance of the
> class, the same instance should be returned to the user.
>
> My doubt is, whether the scope of the class object instantiated in a JSP
> will be limited to that page only or class object can be accessed if
> exists, in subsequent pages also.
>
> Please clarify.
> Thanks in advance
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets