User Guide

Table Of Contents
Interoperating with JSP pages and servlets 925
Calling a JSP page from a ColdFusion page
The following page sets Request, Session, and application variables and calls a JSP page, passing it
a name parameter:
<cfapplication name="myApp" sessionmanagement="yes">
<cfscript>
Request.myVariable = "This";
Session.myVariable = "is a";
Application.myVariable = "test.";
GetPageContext().include("hello.jsp?name=Bobby");
</cfscript>
Reviewing the code
The following table describes the CFML code and its function:
The hello.jsp page is called by the ColdFusion page. It displays the
name parameter in a header
and the three variables in the remainder of the body.
<%@page import="java.util.*" %>
<h2>Hello <%= request.getParameter("name")%>!</h2>
<br>Request.myVariable: <%= request.getAttribute("myVariable")%>
<br>session.myVariable: <%=
((Map)(session.getAttribute("myApp"))).get("myVariable")%>
<br>Application.myVariable: <%=
((Map)(application.getAttribute("myApp"))).get("myVariable")%>
Code Description
<cfapplication name="myApp"
sessionmanagement="yes">
Specifies the application name as myApp and enables
session management. In most applications, this tag is in the
Application.cfm page.
<cfscript>
Request.myVariable = "This";
Session.myVariable = "is a";
Application.myVariable =
"test.";
Sets ColdFusion Request, Session, and Application, scope
variables. Uses the same name, myVariable, for each
variable.
GetPageContext().include
("hello.jsp?name=Bobby");
</cfscript>
Uses the GetPageContext function to get the current servlet
page context for the ColdFusion page. Uses the
include
method of the page context object to call the hello.jsp page.
Passes the name parameter in the URL.