Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

Session Initialization

A session object is created each time the application receives a component action request from a new user. An application may have multiple sessions running concurrently. The session ends when a session time-out value is reached.

Note: By default, applications create session objects during the first cycle of the request-response loop. This is because by default, the first request is handled by the component action request handler, which creates a session. If you change the default request handler to the direct action request handler, you do not have a session object. See "WebObjects Viewed Through Its Classes" for clarification.

In the session object's init method, you set the session's time-out value and initialize variables that should have unique values for each session. For example, if you wanted to have each session keep track of what number it is, you could do so in the session object's init method:

//WebScript Session.wos
- init {
id woApp = [WOApplication application];
self = [super init];
[self setTimeOut:120]; // session idle time is 2 minutes.
[woApp setSessionCount:[woApp sessionCount + 1];
sessionNumber = [woApp sessionCount];
return self;
}
//Java Session.java
public Session() {
super();
Application woApp = (Application)WOApplication.application();
this.setTimeOut(120);
woApp.setSessionCount(woApp.sessionCount() + 1);
sessionNumber = woApp.sessionCount();
}

Table of Contents Next Section