Search code examples
eclipsetomcatservletshttpsession

lost in deployment: session.getAttribute() returns NULL in some Tomcat configurations


I am experiencing several issues that I can't understand from the first glances. The story is pretty simple, but I guess that the solution is behind some real configuration/deployment problem(s)/inconsistencies.

I have defined a JSP and two servlets. The JSP puts something in the session and the servlets are supposed to fetch the data and to manipulate it. The main symptom is that the servlets do not see the session data, when seeing JSPs in Chrome and Firefox. Interesting, that the JSP/servlets do share the data, when using Eclipse internal browser and also when using Internet Explorer (working on Win7).

Here is a bit long description along with some information (and subsequent symptoms) regarding the local configuration (and, as I believe, there lies the problem): I have installed Eclipse (Helios) under c:\labs\eclipse and unpacked Tomcat (7.0.12) under c:\labs\tomcat. I have also installed the Sysdeo plugin that launches Tomcat.

First, when I launch Tomcat with Sysdeo Eclipse plugin button and then try to access some application-related URL from an external browser - then the main Tomcat page is found, but not the application JSP/pages. However, when I launch Tomcat using the "play/run" Eclipse button (when some JSP page from the Eclipse web project is being selected) - then I can see the rendered JSP page both from Eclipse internal browser AND from any external browser. What is the difference between those two launch modes?

Second, when launching Tomcat via "play/run" Eclipse button only, and calling JSP and servlets either from an internal Eclipse browser or from external Internet Explorer browser, then all the data is being shared correctly by JSP and servlets. However (just for the same launch mode) if I am trying to access the JSP/servlets from external Chrome/Firefox browsers - then the JSP/servlets ARE found, but the data seems NOT to be shared via http session (printed the session id and verified that it is correct).

Third, when I launch Tomcat via "pay/run" button, then I can see the servlet log() printings in Eclipse console ONLY when using the internal Eclipse browser. When JSP/servlets are called from the external browsers - I couldn't find the log printings (but only a few access-related lines in files that reside in Tomcat logs directory).

Tried to summarize the tech issues that look odd to me - I most probably miss some valuable deployment/configuration-related info. Please advice what I am doing wrong and which is the better / correct configuration that will allow the session data to be shared when calling the application resources from all the external browsers. If you need any additional details regarding my configuration/environment - just ask.

Appreciate


Solution

  • Ensure that you're using Eclipse for Java EE developers, not Eclipse for Java developers. It already ships with a Tomcat server plugin builtin. The Sysdeo plugin is pretty old, you don't need it at all and I won't be surprised if that is after all the culprit some of the described problems.

    As to running JSP/Servlet using the internal Eclipse browser versus a normal webbrowser, I have myself had bad experiences with the internal browser, I wouldn't recommend to use it for other than "quick testing". However, that it doesn't share the session with another browser is normal behaviour. They do not share the same browser instance anyway. Sessions are not computer-specific, they are browser-specific.

    I'd just integrate Tomcat in Eclipse using the EE-provided plugin, start and stop it by the server properties (and not by rightclicking JSP/Servlet and choosing Run or something) and use a real webbrowser to access the pages. To properly getting started with developing JSP/Servlet using Eclipse and Tomcat, I warmly recommend you to use the Coreservlets.com tutorials. At the bottom of our servlets wiki page you can find several direct links.