I am setting a session in the jsp using scriplet in IBM WCS and setting a value here but when reloading the page the session value is getting lost .
here is how I am setting session attribute
<%
session.setAttribute("testMap", testValue);
%>
However on my local toolkit Its works fine ,but when it is deployed to server having this issue
Please suggest any solution regarding this
Thanks Ankit
Session state in Websphere Commerce is saved in the Business Context, which is tied to the users ActivityToken.
Session state is serialized to the database, and will be available if the users session goes to another server in the cluster.
You can add your own session state by registering a new context element in BusinessContext.xml in the WC\xml\config\BusinessContext.xml, like so:
Then you need to tell which kinds of sessions your Context will be present in
The context will be created along with all other contexts, and will be serialized to either the CTXDATA database table (for known users) and in a browser cookie for anonymous users.
Your context class should look something like this:
An interface class com.myorg.commerce.context.mycontextimpl.MyContext
And an implementation public class MyContextImpl extends AbstractContextImpl implements MyContext { }
After setting a new value, use "this.setDirty(true)" to flag the changes for persistance.
You must also override getContextAttributes to return the values of your context that needs to be serialized, and the setContextAttributes to re-establish the values.
The point is, that the context does more than simply store values. You put invariants in the context, that should hold true for all aspects of the users interaction with the site. The best example is the EntitlementContext, which holds which contract(s) you are buying under, which can be rather complicated to calculate.
Anyway, to access your context from a command, you'd use
And from a jsp
after which you can use it as ${myContext.someValue}