| Contents > Developing ColdFusion MX Applications > Integrating J2EE and Java Elements in CFML Applications > Interoperating with JSP pages and servlets > Examples: using JSP with CFML 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>
The following table describes the CFML code and its function:
Code |
Description |
|---|---|
<cfapplication name="myApp" |
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 |
Uses the |
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")%>
The following table describes the JSP code and its function (line breaks added for clarity):
Code |
Description |
|---|---|
<%@page import="java.util.*" %> |
Imports the java.util package. This contains methods required in the JSP page. |
<h2>Hello <%= request.getParameter |
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 |
<br>request.myVariable: <%= request. |
Uses the 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: |
Uses the 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: <%= |
Uses the 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. |
|
|
||
| Contents > Developing ColdFusion MX Applications > Integrating J2EE and Java Elements in CFML Applications > Interoperating with JSP pages and servlets > Examples: using JSP with CFML Calling a JSP page from a ColdFusion page |
|
|
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.