Advertisement

05.21.2004 at 08:30AM PDT, ID: 20997780
[x]
Attachment Details

Session Problems

Asked by asimalp in Java Server Pages (JSP)

Tags: session, jsp, tomcat, problems

I'm having a problem with my sessions.  I'm using Tomcat 5.0.24 on Windows.  Here is the nature of the problem:

I have a chat application whose context can be added to different web sites as /chat.  For example www.domain.com/chat.

In my chat application, I preper to create a single ChatServlet object per session.  Here is my code at the JSP side:

ChatServlet cs;
if (session.getAttribute("ChatServlet") == null) {
  cs = new ChatServlet();
  session.setAttribute("ChatServlet", cs);
} else {
  cs = (ChatServlet) session.getAttribute("ChatServlet");
}

On my Tomcat, here is the host section of my server.xml.

<Host name="www.domain.com" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true">
  <Logger className="org.apache.catalina.logger.FileLogger" directory="logs"  prefix="DOMAIN_" suffix=".log" timestamp="true"/>
            
  <Context path="/chat" docBase="chat" debug="0" caseSensitive="false" />
  <Context path="" docBase="domain/web" debug="0" caseSensitive="false" />
</Host>

I DO NOT need the crosscontext="true" attribute in the context tag.  I tried doing this, but it didn't solve my problem.

Here is what happens:

I start a new browser window.  Go to www.domain.com/chat.  Everything works perfectly fine.  I have a single session, and the same ChatServlet object is carried through out the session.

Then I close the browser window.  I make sure that the session no longer exists.  Go to www.domain.com (which is the default context).  Browse domain.com without any problems.  However, when I click on the Chat link (which of course points to www.domain.com/chat), a new session (hence a ChatServlet object) is created each time a jsp page from /chat is loaded.  This screws up my chat application.

It doesn't matter for me to have the same session for both contexts.  Context / and /chat don't need to share anything even though it wouldn't matter if they did share the same session, too.  However, I definetely need to have a single session for the entire /chat context.

I hope my explanation is clear.  Please help! :)Start Free Trial
[+][-]05.21.2004 at 08:47AM PDT, ID: 11127821

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2004 at 10:29AM PDT, ID: 11128635

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2004 at 12:36PM PDT, ID: 11129656

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2004 at 01:00PM PDT, ID: 11129832

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Server Pages (JSP)
Tags: session, jsp, tomcat, problems
Sign Up Now!
Solution Provided By: rjkimble
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.22.2004 at 12:09AM PDT, ID: 11132201

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2004 at 04:53PM PDT, ID: 11135690

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2004 at 04:50PM PDT, ID: 11139488

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32