会话正在IBM Websphere Commerce中重置

时间:2014-01-08 06:47:26

标签: websphere websphere-6.1 websphere-commerce

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

这是我如何设置会话属性

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

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

请建议任何有关此问题的解决方案

由于 ANKIT

2 个答案:

答案 0 :(得分:0)

简短的回答是不要这样做。 WebSphere Commerce通常部署在分布式环境中,您可能会在部署代码时看到这种影响。应用程序在WebSphere节点上持久化会话需要做很多工作。而是使用cookie或创建数据库表。你想在那个必须在会话中的地图中存储什么。

答案 1 :(得分:0)

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" />

然后你需要告诉

中你的Context会出现哪种类型的会话
<!-- 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}