Uniface URL-Based State Management
A session is a lasting connection between a Web user and Uniface Web Application Server. It starts when a user starts to access a Web application and ends when the browser is closed, the time is expired, or the user logs out. Uniface generates a session ID for each session.
Note: URL-based state management is not supported for dynamic server pages.
The session ID is passed between the browser and the
Uniface Web Application Server with each HTTP request and response in the same session. You can use
$webinfo("WEBSERVERCONTEXT")
to get the session ID.
SESSIONCOOKIE and SESSION
WEBSERVERCONTEXT is a string containing SESSION, SESSIONCOOKIE and other variables.
- SESSIONCOOKIE is a server variable
defined in the servlet specification of
web.xml.
For example, suppose the servlet is wrd and the Web server is Tomcat. To set it to
false
, in UnifaceInstallDir\uniface\webapps\uniface\WEB-INF\web.xml, insert the following in the servlet wrd’s definition.<init-param> <param-name>SESSIONCOOKIE</param-name> <param-value>false</param-value> </init-param>
- SESSION is a unique ID. It can be passed to the browser as a cookie, or a query string following the URL depending on the value of SESSIONCOOKIE.
SESSIONCOOKIE Value | Cookies allowed on browser client | Cookies not allowed on browser client |
---|---|---|
true
|
cookie | cookie |
false
|
URL query string | URL query string |
dynamic
|
cookie | URL query string |
SESSION as URL Query-String
If the SESSIONCOOKIE is
False
(or Dynamic
and cookies are not allowed in the browser),
instead of treating the session ID as a cookie, Uniface places it as a query string inside the
<form>
tag of the generated HTML page. The format is:
Component-Name?USESSION=sessionID
Suppose the server page name is MY_USP, the
<form>
tag is, for example:
<form method="POST" action="MY_USP?USESSION=53D7EEB3192911D5BA4200C04F514AE7" onSubmit="return uSubmit(this)">
If SESSION is treated as a cookie, this <FORM> tag is:
<form method="POST" action="MY_USP" onSubmit="return uSubmit(this)">
On the browser side, when the user clicks a button to submit the form to the server, the session ID is sent to the server as a query string in the URL with other HTTP request information; for example:
http://HostServer:8080/uniface/wrd/run/MY_USP?SESSION=53D7EEB3192911D5BA4200C04F514AE7
When Uniface receives this request, it assigns
53D7EEB3192911D5BA4200C04F514AE7
to the SESSION variable in
WEBSERVERCONTEXT
. You can read it using
$webinfo("WEBSERVERCONTEXT").
Passing SESSION in Hyperlink
In the URL-based mechanism, only when clicking a submit button, the session ID is automatically attached with the URL in the request. If the user clicks a hyperlink to another server page or back to the same page, the session ID is not included in the URL. You can program Proc to add the session ID in all hyperlinks that need the session ID.
This example shows how to attach a session ID to a hyperlink.
Suppose HLINK is a hyperlink that links to MY_USP Server Page.
- Set the Link Value
property of the Hyperlink Web control to
%%@$fieldname
- In HLINK's Format trigger, write the following
Proc code.
variables String sessioncookie String usession endvariables getitem/id sessioncookie,$webinfo("webservercontext"),"SESSIONCOOKIE" getitem/id usession, $webinfo("webservercontext"),"SESSION" if (sessioncookie = "false") HLINK="http://localhost:8080/uniface/wrd/run/MY_USP?USESSION=%%usession" else HLINK="http://localhost:8080/uniface/wrd/run/MY_USP" endif
If SESSIONCOOKIE is
false
, the session ID is attached to the URL to MY_USP. You can read it using
$webinfo(input)
.