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("Cha
tServlet")
== null) {
cs = new ChatServlet();
session.setAttribute("Chat
Servlet", cs);
} else {
cs = (ChatServlet) session.getAttribute("Chat
Servlet");
}
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.cata
lina.logge
r.FileLogg
er" 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