User Guide

Table Of Contents
926 Chapter 37: Integrating J2EE and Java Elements in CFML Applications
Reviewing the code
The following table describes the JSP code and its function (line breaks added for clarity):
Calling a ColdFusion page from a JSP page
The following JSP page sets Request, Session, and application variables and calls a ColdFusion
page, passing it a name parameter:
<%@page import="java.util.*" %>
<% request.setAttribute("myvariable", "This");%>
<% ((Map)session.getAttribute("myApp")).put("myVariable", "is a");%>
<% ((Map)application.getAttribute("myApp")).put("myVariable", "test.");%>
Code Description
<%@page import="java.util.*" %>
Imports the java.util package. This contains methods
required in the JSP page.
<h2>Hello <%= request.getParameter
("name")%>!</h2>
Displays the name passed as a URL parameter from the
ColdFusion page. The parameter name is case-sensitive,
Note: The
getParameter request method cannot get all
ColdFusion page request parameter values on some
application servers. For example, on IBM WebSphere,
you cannot use
getParameter to get form fields.
<br>request.myVariable: <%= request.
getAttribute("myvariable")%>
Uses the getAttribute method of the JSP request
object to displays the value of the Request scope
variable myVariable.
The JSP page must use all lowercase characters to refer
to all request scope variables that it shares with CFML
pages. You can use any case on the CFML page, but if
you use mixed case to all uppercase on the JSP page,
the variable will not get its value ColdFusion page.
<br>session.myVariable:
<%=
((Map)(session.getAttribute("myApp
"))).
get("myVariable")%>
Uses the getAttribute method of the JSP session
object to get the myApp object (the Application scope).
Casts this to a Java Map object and uses the get method
to obtain the myVariable value for display.
CFML pages and JSP pages share Session variables
independent of the variable name case. The variable on
the JSP page can have any case mixture and still receive
the value from the ColdFusion page. For example,
instead of myVariable, you could use MYVARIABLE or
myvariable on this line.
<br>Application.myVariable: <%=
((Map)(application.getAttribute("m
yApp")))
.get("myVariable")%>
Uses the getAttribute method of the JSP myApp
application object to obtain the value of myVariable in
the Application scope.
CFML pages and JSP pages share Application variables
independent of the variable name case. The variable on
the JSP page can have any case mixture and still receive
the value from the ColdFusion page. For example,
instead of myVariable, you could use MYVARIABLE or
myvariable on this line.