
313
DEVELOPING
COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Las
t
upda
te
d 8/5/2010
Selecting and enabling session variables in ColdFusion Administrator
To use session variables, they must be enabled on the ColdFusion Administrator Memory Variables page. (They are
enabled by default.) You can also use the Administrator Memory Variables page to do the following:
•
Select to use ColdFusion session management (the default) or J2EE session management.
•
Change the default session time-out. Application code can override this value. The default value for this time-out
is 20 mins.
•
Specify a maximum session time-out. Application code cannot set a time-out greater than this value. The default
value for this time-out is two days.
Enabling session variables in your application
Enable session variables in the initialization code of your Application.cfc file or in the
cfapplication
tag in your
Application.cfm file.
Do the following in the Application.cfc initialization code, below the
cfcomponent
tag, to enable session variables:
•
Set This.sessionManagement="Yes".
•
Set This.name to specify the name of the application.
•
Optionally, set This.sessionTimeout to set an application-specific session time-out value. Use the
CreateTimeSpan
function to specify the number of days, hours, minutes, and seconds for the time-out.
Do the following in the Application.cfm file to enable session variables:
•
Set
sessionManagement="Yes"
•
Use the
name
attribute to specify the name of the application.
•
Optionally, use the
sessionTimeout
attribute to set an application-specific session time-out value. Use the
CreateTimeSpan
function to specify the number of days, hours, minutes, and seconds for the time-out.
The following sample code enables session management for the GetLeadApp application and sets the session variables
to time out after a 45-minute period of inactivity:
<cfapplication name="GetLeadApp"
sessionmanagement="Yes"
sessiontimeout=#CreateTimeSpan(0,0,45,0)#>
Storing session data in session variables
Session variables are designed to store session-level data. They are a convenient place to store information that all
pages of your application might need during a user session, such as shopping cart contents or score counters.
Using session variables, an application can initialize itself with user-specific data the first time a user accesses one of
the pages of the application. This information can remain available while that user continues to use that application.
For example, you can retrieve information about a specific user’s preferences from a database once, the first time a user
accesses any page of an application. This information remains available throughout that user’s session, thereby
avoiding the overhead of retrieving the preferences repeatedly.
Standard session variables
If you use ColdFusion session variables, the Session scope has four built-in, read-only variables that your application
can use. If you use J2EE session management, the Session scope has two built-in variables. Generally, you use these
variables in your ColdFusion pages only if your application supports browsers that do not allow cookies. For more
information on supporting browsers that do not allow cookies, see “
Using client and session variables without cookies
”
on page 305. The following table describes the built-in session variables.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...