# Function java_session

Return a session handle.

When java_session() is called without arguments, the session is shared with java. Example:

    java_session()->put("key", new Java("java.lang.Object"));
    [...]

The java components (jsp, servlets) can retrieve the value, for example with:

    getSession().getAttribute("key");

When java_session() is called with a session name, the session is not shared with java and no cookies are set. Example:

    java_session("myPublicApplicationStore")->put("key", "value");

When java_session() is called with a second argument set to true, a new session is allocated, the old session is destroyed if necessary. Example:

    java_session(null, true)->put("key", "val");

The optional third argument specifies the default lifetime of the session, it defaults to

    session.gc_maxlifetime

. The value 0 means that the session never times out.

The synchronized init() and onShutdown() callbacks from java_context() and the JPersistenceAdapter (see JPersistenceAdapter.php from the php_java_lib directory) may also be useful to load a Java singleton object after the JavaBridge library has been initialized, and to store it right before the web context or the entire JVM will be terminated.

License: GPL
Author: Jost Boekemeier
See: java_
See: `java_context()`
Located at JavaProxy.inc