First of all, thank you so much Alexander for taking the time to explain 
this so thoroughly.


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

Lovely concise answer. I've printed this out as a cheat sheet :-)

Now, since each JSP is essentially a servlet, how does the servlet perform 
the sharing of the javabean ? Does a servlet that shares a javabean (similar 
to the JSP case [d] above, where scope="application"), is actually creating 
the javabean as a *static* variable so that it is shared by all members of 
the class ?


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


Great, that's what I thought.  But here's why I'm getting confused. The 
servlet tutorial says that a servlet is created once and once only (that's 
when the init() is run).
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.html
If the servlet class is created only once, how does Tomcat then create 
multiple instances of the class ?

>I could recommend a german book here, but I think that wouldn't be of
>great use for you...

Good guess. Learning German through Java would surely be a challenge :)

Thank you again, Soefara.


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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

Reply via email to