luke olegario wrote:
>
> Hi,
>
> I am very new to JSP and JavaBeans development. I hope anyone could
> enlighten me with some of my questions.
>
> How does the JavaBeans specified inside the JSP operates? Will there be
> only a single instance of the bean that will be loaded and all requests from
> JSP pages will be handled one at a time (if this is the case, this is a very
> slow and painful process, isn't it?), or will there be multiple instances of
> the bean for each JSP page that requested its services.
You control the number of instances of a bean with the scope attribute of
<jsp:useBean>. The number of instances depends on the scope like this:
* page, one instance is created per request and is available during
processing of the page where it's created,
* request, one instance is created per request and is available during
processing of the request (even if it spans pages, e.g. through <jsp:include>)
* session, one instance is created per user session, i.e. a sequence of
related requests
* application, one instance is created and shared by all users and all
requests.
Since session scope and application scope beans are shared by multiple
requests you must make sure they are implemented in a thread-safe manner.
> Furthermore, are
> JSP pages also loaded only once just like a servlet, and http requests
> handled using several service() threads. If JSP pages also invoke several
> service threads() to handle requests, is it safe to assume that the bean
> used in the JSP page will also be multiple instances, with each instance
> being independent of the other bean instance.
A JSP page implementation class is a servlet and is handled as a servlet,
in other words, only one instance is created and each request runs a
separate thread through its service() method (ignoring the case when you
use <%@ page isThreadSafe="no" %>, but that's a different story).
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
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