Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Session setAttribute scope - Tomcat

Thread view: 
nobrentl@legacysol.net - 24 Jun 2006 00:05 GMT
In Tomcat 5.5 using several minor releases under both Windows and Linux
I am using the "session" variable in .jsps as provided in Tomcat's
default configuration, then setting and getting attributes.  I can see
with multiple sessions that each instance gets a different session id
by displaying the session id via out.println(session).  However, they
seem to share same attribute scope as if I am accessing an application
scoped context.  Hence, if one session sets an Attribute (eg.
session.setAttribute("msg","test1")), and then subsequently another
session gets that Attribute (eg. session.getAttribute("msg")), it gets
the other session's value (eg "test1") not the what it previously set
that attribute to.

Tomcat generates java as follows for the "session" variable as follows:

     _jspxFactory = JspFactory.getDefaultFactory();
     response.setContentType("text/html");
     pageContext = _jspxFactory.getPageContext(this, request,
response,
                 null, true, 8192, true);
     _jspx_page_context = pageContext;
     application = pageContext.getServletContext();
     config = pageContext.getServletConfig();
     session = pageContext.getSession();

What's up? Thanks.
nobrentl@legacysol.net - 24 Jun 2006 15:20 GMT
My problem was statically declared variables within a messaging class
responsible for saving the system state between requests.  Static
equates to one variable instance per VM.
Juha Laiho - 25 Jun 2006 13:10 GMT
nobrentl@legacysol.net said:
>My problem was statically declared variables within a messaging class
>responsible for saving the system state between requests.  Static
>equates to one variable instance per VM.

Actually one variable per loaded class instance, and there are cases
where a single class is loaded multiple times in a single VM by different
classloaders (this is especially typical in servlet applications,
where the server creates a separate classloader for each deployed
application, but all the applications still run in a single VM).
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.