Documentation

(jvx:server:lco)

Using SessionContext

Translations of this page:

SessionContext is an object available only at the server that enables access to session information as well as certain objects related to a session during the handling of a client request.

Example

We have developed an application that reviews all existing messages in an email account and displays the number of messages. The request is initiated at the client by clicking a button.

The call using a button is illustrated in Client Actions or Server Actions

The server action accesses the mail server; the required access data is obtained from the application configuration.

Sample code for the server action:

/**
 * Returns the number of mails from a preconfigured email account.
 *  
 * @return the number of mails
 */
public int getEmailCount()
{
   IConfiguration cfgSession = SessionContext.getCurrentSessionConfig();
 
   String sServer = cfgSession.getProperty("/application/email/server");
   String sPort = cfgSession.getProperty("/application/email/port");
   String sProtocol = cfgSession.getProperty("/application/email/protocol");
   String sUser = cfgSession.getProperty("/application/email/username");
   String sPwd = cfgSession.getProperty("/application/email/password");
 
   MailCheck mcheck = new MailCheck(sServer, sPort, sProtocol);
 
   return mcheck.getMails(sUser, sPwd).size();
}   

Excerpt from the configuration file:

  ...
  ...
 
  <email>
    <server>servername or ip</server>
    <port>110</port>
    <protocol>pop3</protocol>
    <username>username</username>
    <password>password</password>
  </email>
 
</application>

SessionContext Life Cycle

Additional Examples

SessionContext can also be used for the following:

  • Access session properties (e.g., application name, username, client properties)
  • Request the name of the current action
  • Access the server configuration
  • Use of the direct server connection
  • Add or remove objects related to a call
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information