Session setAttribute scope - Tomcat

N

nobrentl

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

nobrentl

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

Juha Laiho

(e-mail address removed) 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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top