Narong Chansoi wrote:
>
> Hi,
>
> Can JSP and Servlet share same Session and Beans?
> Example: I used Beans and Session with my servlet, JSP can use same Beans
> and Session or not?
>
> Thanks in advance,
>
> Narong Chansoi
>
This can be done, but you are likely to run into problems with
class loaders. For instance, we have Apache/JServ which uses the
AdaptiveClassLoader along with GNU-JSP which has a different class
loader. If you just casually allocate objects in a servlet and
then pick them up in JSP pages, you'll most likely get the
dreaded ClassCastException, which signals the VM's pleasure when
you try to cast a class that was brought in by a different class
loader.
Note that there are sometimes problems even within JSP, as GNU-JSP
drops the class loader every time you recompile a page, so if
you allocated a class instance using one version of the page, then
recompiled and tried to fish that instance back again, you would
either (1) not find it or (2) get the ClassCastException (but
see para #1 above).
If you really need to pass information around, the best way for
Apache and GNU-JSP is to do the following:
(1) Have one server per person when developing.
(2) Make sure that all your Java classes, including servlet code,
load through the system class path. This means they load
through the primordial loader, which does not go away or
change.
(3) Make sure that your compiled JSP pages go to another location
than your regular Java classes. That way, the JSP loader
will just pick them up through the primordial loader.
In this scheme, you will need to reboot the Web server each time
you make a change to the regular Java classes or else great
confusion will ensue. (And possibly outrage among your users,
I might add.)
If you need to share a Web Server between multiple people, or
cannot reboot whenever you make class changes, the solution is
much more complex. I can post a treatise on one approach at a later
time (big project, deadline Friday) if there is interest.
Hope this helps,
Robert Hodges
Tilden Park Software
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".