User Guide

Table Of Contents
924 Chapter 37: Integrating J2EE and Java Elements in CFML Applications
Accessing ColdFusion application and session variables in JSP pages
ColdFusion MX runs as a J2EE application on the J2EE application server. The J2EE application
ServletContext is a data structure that stores objects as attributes. A ColdFusion Application
scope is represented as an attribute named by the Application scope name. The attribute contains
the scope values as a hash table. Therefore, you access ColdFusion Application scope variable in a
JSP page or servlet using the following format:
((Map)application.getAttribute("CFApplicationName"))).get("appVarName")
Similarly, the ColdFusion Session scope is a structure within the J2EE session. Because
ColdFusion MX identifies sessions by the application name. the session structure is contained in
an attribute of the J2EE session that is identified by the application name. Therefore, you access
ColdFusion session variables as follows:
((Map)(session.getAttribute("CFApplicationName"))).get("sessionVarName")
Unnamed ColdFusion Application and Session scopes
If you do not specify an application name in the This.name variable in the Application.cfc
initialization code or by using the ColdFusion
cfapplication tag, the application is unnamed,
and the Application scope corresponds to the ColdFusion MX J2EE servlet context.
ColdFusion MX, therefore, supports only a single unnamed application. If multiple
cfapplication tags and Application.cfc files do not specify an application name, all pages in
these applications share the servlet context as their Application scope.
All sessions of unnamed applications correspond directly to the J2EE application server’s session
object. (If you do not use J2EE session variables, ColdFusion MX ensures that the J2EE session
lasts at least as long as the session time-out.)
You access an Application scope variable from a ColdFusion unnamed application in a JSP page
using the following format:
application.getAttribute("applicationVariableName")
You access Session scope variables in a ColdFusion unnamed application as follows:
session.getAttribute("sessionVariableName")
Note: When you use application and session variables for the unnamed ColdFusion application in
JSP pages and servlets, the variable names must be case-correct. That is, the characters in the
variable name must have the same case as you used when you created the variable in ColdFusion.
You do not have to use case-correct application and session variable names for named ColdFusion
applications.
Examples: using JSP with CFML
The following simple examples show how you can integrate JSP pages, servlets, and ColdFusion
pages. They also show how you can use the Request, Application, and Session scopes to share data
between ColdFusion pages, JSP pages, and servlets.