部署中丢失:session.getAttribute() 在某些 Tomcat 配置中返回 NULL

发布于 2024-11-05 18:33:59 字数 1246 浏览 5 评论 0原文

我遇到了一些第一眼无法理解的问题。这个故事非常简单,但我猜想解决方案背后是一些真正的配置/部署问题/不一致。

我定义了一个 JSP 和两个 servlet。 JSP 将某些内容放入会话中,servlet 应该获取数据并对其进行操作。主要症状是 servlet 在 Chrome 和 Firefox 中查看 JSP 时看不到会话数据。有趣的是,当使用 Eclipse 内部浏览器以及使用 Internet Explorer(在 Win7 上工作)时,JSP/servlet 确实共享数据。

这里有一个有点长的描述以及一些关于本地配置的信息(和后续症状)(并且,我相信,这就是问题所在):我已经在 c:\labs\eclipse 下安装了 Eclipse (Helios) 并解压了 Tomcat ( 7.0.12) 在 c:\labs\tomcat 下。我还安装了启动 Tomcat 的 Sysdeo 插件。

首先,当我使用 Sysdeo Eclipse 插件按钮启动 Tomcat,然后尝试从外部浏览器访问一些与应用程序相关的 URL 时,会找到 Tomcat 主页面,但找不到应用程序 JSP/页面。但是,当我使用“播放/运行”Eclipse 按钮​​启动 Tomcat 时(当选择 Eclipse Web 项目中的某些 JSP 页面时),我可以看到渲染的 JSP 页面两者< /em> 来自 Eclipse 内部浏览器和任何外部浏览器。这两种启动模式有什么区别?

其次,当仅通过“播放/运行”Eclipse 按钮​​启动 Tomcat,并从内部 Eclipse 浏览器或外部 Internet Explorer 浏览器调用 JSP 和 servlet 时,所有数据都由 JSP 正确共享和 servlet。但是(仅对于相同的启动模式)如果我尝试从外部 Chrome/Firefox 浏览器访问 JSP/servlet - 那么会找到 JSP/servlet,但数据似乎不会通过 http 会话共享(打印会话 id)并验证其正确性)。

第三,当我通过“pay/run”按钮启动 Tomcat 时,仅当使用内部 Eclipse 浏览器时,我才能在 Eclipse 控制台中看到 servlet log() 打印。当从外部浏览器调用 JSP/servlet 时,我找不到日志打印(但只有 Tomcat 日志目录中的文件中的一些与访问相关的行)。

试图总结对我来说看起来很奇怪的技术问题 - 我很可能错过了一些有价值的部署/配置相关信息。请告知我做错了什么,以及哪个更好/正确的配置将允许在从所有外部浏览器调用应用程序资源时共享会话数据。如果您需要有关我的配置/环境的任何其他详细信息 - 请询问。

欣赏

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚如初 2024-11-12 18:33:59

确保您使用的是 Eclipse for Java EE 开发人员,而不是面向 Java 开发人员的 Eclipse。它已经内置了 Tomcat 服务器插件。 Sysdeo 插件相当老了,你根本不需要它,如果它是所描述的一些问题的罪魁祸首,我也不会感到惊讶。

至于使用内部 Eclipse 浏览器与普通 Web 浏览器运行 JSP/Servlet,我自己对内部浏览器有过不好的经历,除了“快速测试”之外,我不建议将其用于其他目的。但是,它不与其他浏览器共享会话是正常行为。无论如何,它们不共享相同的浏览器实例。会话不是特定于计算机的,而是特定于浏览器的。

我只是使用 EE 提供的插件将 Tomcat 集成到 Eclipse 中,通过服务器属性启动和停止它(并且通过右键单击 JSP/Servlet 并选择运行或其他内容)并使用真正的网络浏览器访问页面。为了正确开始使用 Eclipse 和 Tomcat 开发 JSP/Servlet,我强烈建议您使用 Coreservlets.com 教程。在我们的 servlet wiki 页面 的底部,您可以找到几个直接链接。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文