Adobe COLDFUSION 9 Manual page 1138

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Code
<%@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("m
yApp"))).get("myVariable")%>
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.");%>
<jsp:include page="hello.cfm">
<jsp:param name="name" value="Robert" />
</jsp:include>
Reviewing the code
The following table describes the JSP code and its function:
Description
Imports the java.util package. This package contains methods required in the JSP page.
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.
Uses the
method of the JSP request object to displays the value of the
getAttribute
Request scope variable myVariable.
The JSP page must use all lowercase characters to reference 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 or all uppercase on the JSP page, the variable is not set from the ColdFusion
page.
Uses the
method of the JSP session object to get the myApp object (the
getAttribute
Application scope). Casts this object 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.
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.
Last updated 8/5/2010
1133

Advertisement

Table of Contents
loading

Table of Contents