ian said:
Yes, I'm being a bit intuitive about this, trying to avoid a mountain
of reading for what is a reasonably simple try-out.
I have tried to ask my question as clearly as possible. I've also tried
to make some semi-intelligent guesses about what seems to be happening
based on what (little) I do know. If what I've described doesn't seem
odd to you then I think I probably do need to go into this a bit more
as it doesn't seem very logical to me.
1) You do not need to use beans to use JSP.
2) If you do use beans in your JSP, you need to understand what the
various values of the scope attribute mean:
+ application: A bean instance associated with the specified id is
sought in the application (via its ServletContext). If found, that
instance is used in the page, otherwise a new instance is created,
stored in the application and used in the page as it services the
current request. The same instance may later be used by any page or
servlet in the same webapp.
+ session: A bean instance associated with the specified id is sought
in the session (via its HttpSession). If found, that instance is used
in the page, otherwise a new instance is created, stored in the session
and used in the page as it services the current request. The same
instance may later be used by any page or servlet in the same webapp,
while servicing another request in the same session. Other distinct
bean instances may be associated with the same name in other sessions.
+ request: A bean instance associated with the specified id is sought in
the request (via its HttpServletRequest). If found, that instance is
used in the page, otherwise a new instance is created, stored in the
request and used in the page as it services the current request. The
same instance may later be used by any page or servlet in the same
webapp, while servicing the same HTTP request (which can happen when a
JSP forward or include is used -- but do not confuse that with an HTTP
redirect). Other distinct bean instances may be associated with the
same name in other requests.
+ page: A bean instance created and associated with the specified id in
the context of the JSP in which the declaration appears for the duration
of that page's handling of the current request. Every invocation of the
page will cause a distinct bean instance to be created and used, and the
bean instances will not be visible to other pages.
3) I personally find it helpful to keep in mind that JSP pages are
internally translated into Java source for servlets, then compiled to
classes for use by the container. Understanding how JSP syntax and
features map to Java code guides me through some of the intricacies of
JSP. At least some knowledge of these correspondences is essential if
you use JSPs and servlets together in one web application.
4) The ultimate reference material for JSP is the JSP specification,
available free from Sun. The most recent version is 2.0. You may also
want to obtain the Servlet spec, also available from Sun; its most
recent version is 2.4. The size of these specs is a bit daunting, but
they contain a great deal of material that you can skip over if you are
just trying to orient yourself. For servlets, you may also want to get
the HTML version of their API specification; it is part of the J2EE API
spec.