| 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 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>
The following table describes the JSP code and its function:
Code |
Description |
|---|---|
<%@page import="java.util.*" %> |
Imports the java.util package. This contains methods required in the JSP page. |
<% request.setAttribute("myvariable", |
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 JSP page will not share it with the ColdFusion page. |
<% ((Map)session.getAttribute("myApp")) |
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 share the value with the ColdFusion page. For example, instead of myVariable, you could use MYVARIABLE or myvariable on this line. |
<% ((Map)application.getAttribute |
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 share the value with the ColdFusion page. For example, instead of myVariable, you could use MYVARIABLE or myvariable on this line. |
<jsp:include page="hello.cfm">
<jsp:param name="name" value="Robert" />
</jsp:include>
|
Sets the name parameter to Robert and calls the ColdFusion page hello.cfm. |
The following hello.cfm page is called by the JSP page. It displays the Name parameter in a heading and the three variables in the remainder of the body.
<cfapplication name="myApp" sessionmanagement="yes"> <cfoutput> <h2>Hello #URL.name#!</h2> Request.myVariable: #Request.myVariable#<br> Session.myVariable: #Session.myVariable#<br> Application.myVariable: #Application.myVariable#<br> </cfoutput>
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. |
<cfoutput> <h2>Hello #URL.name#!</h2> |
Displays the name passed using the |
Request.myVariable: |
Displays the Request.myVariable, Session. myVariable, and Application.myVariable values. Note that all variable names on CFML pages are case independent. |
|
|
||
| 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 ColdFusion page from a JSP 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.