> First, am I correct in saying that the default behaviour for a
> Javabean is
> that each servlet or JSP that uses it will create a new instance of that
> Javabean ?  For example, if we have Register.jsp which uses a Javabean
> called memberData.java then if 2 people were to submit data to
> Register.jsp
> at exactly the same time, each page would actually create and use
> a separate
> instance of the bean memberData.java. Is this correct?

Nice answer: That depends :-)
a) <jsp:useBean id="mb" class="MyBean" scope="page" />
The bean is created for exactly this page executed by this user

b) <jsp:useBean id="mb" class="MyBean" scope="request" />
The bean is created for this page and all pages you <jsp:include> in this
request.

c) <jsp:useBean id="mb" class="MyBean" scope="session" />
The bean is created and accessible by all pages of this application (You
must include this line into all pages)
p.ex.: You create a session bean that accesses a database. The database
connection will be made once and will stand until the session runs out.
There is a seperate bean for every user, though.

d) <jsp:useBean id="mb" class="MyBean" scope="application" />
The bean is created the first time a user accesses a page in your
application. From then on, every user and every page will have the same
bean!

> Second, if this is the case, how do you actually create a shared bean and
> why would you want one ?

You just have to set a bean's scope to application. Try to think of desired
uses yourself, I don't want to set up an example right now ;-)

> Third, I'm getting confused and starting to doubt my understanding of
> servlets within the Tomcat servlet container. If we have a simple servlet
> using the helloWorld.class and it just prints "hello world" to
> the web page,
> then if 10 people were to requsest the servlet at the same time, am I
> correct in assuming that 10 different instances of the class are
> created to
> handle these requests ?

true

> Sorry for these seemingly basic questions but I'm going through
> one of those
> stages where I question the fundamental understanding. I must go read the
> servlet API I think.

I could recommend a german book here, but I think that wouldn't be of great
use for you...
I think everybody has these phase where he thinks he would never understand
this big pile of information, I currently go through this phase on SOAP ;-)

May the clouds over JSP-valley vanish ;-)
Alexander


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to