Hi,
The document "Introduction to NetDynamics" (Version 4.1) talks about using
PageSession to track the number of users hitting a particular page.
I tried to implement the above functionality using the pagesession object.
The following code shows a Page with a static text field and a button.
//[[SPIDER_CLASS BEGIN
public class BlankPage extends spider.visual.CSpPage
//]]SPIDER_CLASS END
{
//[[SPIDER_EVENTS BEGIN
//[[SPIDER_EVENT<StaticText1_onBeforeDisplayEvent>
public int StaticText1_onBeforeDisplayEvent(CSpDisplayEvent event)
{
CSpValue value = getPageSessionObject("Counter");
if(CSpUtil.nonEmptyString(value))
((CSpDisplayField)event.getSource()).setValue(value);
return (PROCEED);
}
//]]SPIDER_EVENT<StaticText1_onBeforeDisplayEvent>
//[[SPIDER_EVENT<btSubmit_onWebEvent>
public int btSubmit_onWebEvent(CSpWebEvent event)
{
int command = PROCEED;
CSpValue value = getPageSessionObject("Counter");
if(CSpUtil.nonEmptyString(value))
{
((CSpLong)value).increment();
}
else
{
value = new CSpLong(1);
}
putPageSessionObject("Counter", value);
load();
return(command);
}
//]]SPIDER_EVENT<btSubmit_onWebEvent>
//]]SPIDER_EVENTS END
}
The above code does not reflect across all the users accessing the page. The counter
increments only for that user session. I think the correct way to implement the hit
counter is by using globalsession object. Even a static variable in that page will not
be correct, since the number of JVM's (CPWorker's) can be more than one, each one
having its own instance of class.
Please correct me if I am wrong.
Thanks & Regards,
S.Senthil Kumar.
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]