接缝&多次战争:Contexts.getSessionContext() 在其他战争中为 null
我在 Weblogic 10.3.2 和 JSF 1.2 上使用 Seam 2.2.1.CR1。
我有一个带有 2 个 war 文件的耳朵应用程序。第一个战争是 JSF / Seam 应用程序,第二个战争确实有 JSF / Seam,但也有一些 Servlet 页面。
当我在第一个Web应用程序的Session上下文中设置内容时:
Contexts.getSessionContext().set("pimUser", pimUser);
我可以在第二次战争中将它正常注入到Seam组件中。但是,如果我尝试从 Servlet 获取抛出的 pimUser,则无法访问它:
PimUser user1 = (PimUser) Contexts.getSessionContext().get("pimUser");
Contexts.getSessionContext() 为 null。我注意到 Javadoc 说
org.jboss.seam.contexts.Contexts
:
提供对与线程关联的当前上下文的访问。
作者:Gavin King Thomas Heute
这是否意味着 2 个 war 文件应该具有不同的 Contexts.getSessionScope() ?
我找到了一种允许我通过会话访问它的方法,如下所示:
PimUser user2 = (PimUser) httpRequest.getSession().getAttribute("pimUser");
但是后一种方法似乎不是正确的方法。我想通过 Seam 访问 Seam 会话上下文。
我发现 Seam 和 multi-war 应用程序存在问题(链接),但是,这些应该已在 2.2.0.GA 中得到解决。
I am using Seam 2.2.1.CR1 on Weblogic 10.3.2 and JSF 1.2.
I have an ear application with 2 war files. The first war is a JSF / Seam application, the second one does have JSF / Seam, but also has some Servlets pages as well.
When I set things in the Session context in the first web application:
Contexts.getSessionContext().set("pimUser", pimUser);
I can inject it normally in Seam components in the second war. However, if I try to get the outjected pimUser from a Servlet, I cannot access it:
PimUser user1 = (PimUser) Contexts.getSessionContext().get("pimUser");
The Contexts.getSessionContext() is null. I noticed that the Javadoc of the
org.jboss.seam.contexts.Contexts
Says:
Provides access to the current contexts associated with the thread.
Author(s): Gavin King Thomas Heute
Does this mean that the 2 war files are supposed to have different Contexts.getSessionScope()
?
I found a way which does allow me to access it through the Session like this:
PimUser user2 = (PimUser) httpRequest.getSession().getAttribute("pimUser");
The latter way, however does not seem to be a correct one. I would like to access Seam session context through Seam.
I found that there used (?) to be issues with Seam and multi-war applications (link), however, these are supposed to have been resolved by 2.2.0.GA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,常规 servlet 无法访问 Seam 上下文:用 Seam 资源替换 servlet。您需要首先通过将调用包装在Seam上下文中或用 Seam
AbstractResource
替换 servlet。我之前用过这两种方法并且效果很好。就我个人而言,我更喜欢
AbstractResource
因为您可以摆脱相应的web.xml
配置。A regular servlet does not get access to the Seam contexts by default: Replacing servlets with Seam resources. You need to integrate it first by either wrapping the call in Seam Contexts or replacing the servlet with a Seam
AbstractResource
.I used both ways before and they work perfectly. Personally, I prefer the
AbstractResource
because you can get rid of the correspondingweb.xml
configuration.