User Guide

Table Of Contents
922 Chapter 37: Integrating J2EE and Java Elements in CFML Applications
Example: using the random tag library
The following example uses the random tag library from the Apache Jakarta Taglibs project and
calls the library’s
number tag, which initializes a random number generator that uses a secure
algorithm to generate a six-digit random number. You get a new random number each time you
reference the variable randPass.random.
<cfimport taglib="/WEB-INF/lib/taglibs-random.jar" prefix="myrand">
<myrand:number id="randPass" range="000000-999999" algorithm="SHA1PRNG"
provider="SUN" />
<cfset myPassword = randPass.random>
<cfoutput>
Your password is #myPassword#<br>
</cfoutput>
For more information on the Jakarta random tag library and how to use its tags, see the
documentation at the Apache Jakarta Taglibs project website, http://jakarta.apache.org/taglibs/
index.html. The Taglibs project includes many open source custom tag libraries.
Interoperating with JSP pages and servlets
ColdFusion pages and JSP pages can interoperate in several ways:
ColdFusion pages can invoke JSP pages and servlets.
JSP pages can invoke ColdFusion pages.
ColdFusion pages, JSP pages, and servlets can share data in three scopes.
The following sections show how you can use these techniques.
Integrating JSP and servlets in a ColdFusion application
You can integrate JSP pages and servlets in your ColdFusion application. For example, you can
write some application pages in JSP and write others in CFML. ColdFusion pages can access JSP
pages by using the JSP
include and forward methods to call the page. As with any web
application, you can use
href links in ColdFusion pages to open JSP pages.
The ability to use JSP lets you incorporate legacy JSP pages in your ColdFusion application, or
conversely, use CFML to expand an existing JSP application using ColdFusion pages.
If you have a JSP page that must call a ColdFusion page, you also use a
jsp:forward or
jsp:include tag to call the ColdFusion page. For an example of calling a ColdFusion page from
a JSP page, see “Calling a JSP page from a ColdFusion page” on page 925.
Accessing a JSP page or servlet from a ColdFusion page
To access a JSP page or servlet from a ColdFusion page, you use the
GetPageContext function
with the
forward or the include method. For example, to include a JSP “Hello World" page in
your ColdFusion application, use the following line:
GetPageContext().include("hello.jsp");
To pass parameters to the JSP page, include the parameters in the page URL.