【问题标题】:session is getting reset in IBM Websphere CommerceIBM Websphere Commerce 中的会话正在重置
【发布时间】:2014-01-26 03:32:30
【问题描述】:

我正在使用 IBM WCS 中的 scriplet 在 jsp 中设置会话并在此处设置一个值,但是在重新加载页面时会话值丢失了。

这是我设置会话属性的方式

<%
session.setAttribute("testMap", testValue);
%>

但是在我的本地工具包上它工作正常,但是当它部署到有这个问题的服务器时

请提出任何解决方案

谢谢 Ankit

【问题讨论】:

  • 您的页面顶部是否有 声明?
  • 您的生产部署是否集群化?如果是这样,您是否打开了会话亲和性?

标签: websphere websphere-6.1 websphere-commerce


【解决方案1】:

Websphere Commerce 中的会话状态保存在与用户 ActivityToken 相关联的业务上下文中。

会话状态被序列化到数据库中,如果用户会话转到集群中的另一台服务器,它将可用。

您可以通过在 WC\xml\config\BusinessContext.xml 中的 BusinessContext.xml 中注册一个新的上下文元素来添加自己的会话状态,如下所示:

 <BusinessContext ctxId="MyContext"
               factoryClassname="com.ibm.commerce.context.factory.SimpleBusinessContextFactory" >
<parameter name="spiClassname" value="com.myorg.commerce.context.contentimpl.MyContextImpl" />

然后你需要告诉你的上下文将出现在哪些类型的会话中

<!-- web site store front configuration -->
<InitialBusinessContextSet ctxSetId="Store" >
    ...
  <InitialBusinessContext ctxId="MyContext" createOrder="0" />

上下文将与所有其他上下文一起创建,并将被序列化为 CTXDATA 数据库表(对于已知用户)和匿名用户的浏览器 cookie。

您的上下文类应如下所示:

一个接口类 com.myorg.commerce.context.mycontextimpl.MyContext

public abstract interface MyContext extends Context
{
   public static final String CONTEXT_NAME =     "com.myorg.commerce.context.mycontextimpl.MyContext";
   public abstract String getSomeValue();
   public abstract void setSomeValue(String v);
}

还有一个实现 公共类 MyContextImpl 扩展 AbstractContextImpl 实现 MyContext { }

设置新值后,使用“this.setDirty(true)”标记持久性更改。

您还必须重写 getContextAttributes 以返回需要序列化的上下文的值,并重写 setContextAttributes 以重新建立值。

关键是,上下文不仅仅是存储值。您将不变量放在上下文中,这应该适用于用户与站点交互的所有方面。最好的例子是 EntitlementContext,它保存了您购买的合同,计算起来可能相当复杂。

无论如何,要从命令访问上下文,您会使用

this.getCommandContext().getContext(MyContext.CONTEXT_NAME);

从一个jsp

if (request.getAttribute("myContext") == null) {
    request.setAttribute("myContext", ((CommandContext) request.getAttribute("CommandContext")).getContext(MyContext.CONTEXT_NAME));
}

之后您可以将其用作 ${myContext.someValue}

【讨论】:

    【解决方案2】:

    简短的回答是不要这样做。 WebSphere commerce 通常部署在分布式环境中,当您的代码被部署时,您可能会看到这种效果。应用程序要跨 WebSphere 节点保持会话需要做很多工作。而是使用 cookie,或创建数据库表。您要在必须处于会话中的地图中存储什么。

    【讨论】:

      猜你喜欢
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多