ColdFusion和JSP互传数据的两个例子。共同学习。

jscsqb 2003-08-31 10:21:27
1。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 hello.jsp page is called by the CFML. 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")%>

2。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");%>
<% application.setAttribute("myApp.myvariable", "test.");%>
<jsp:include page="hello.cfm">
<jsp:param name="name" value="Robert" />
</jsp:include>
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>


...全文
53 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Karnak 2003-09-04
  • 打赏
  • 举报
回复
总是在jsp调用时抛出request访问出错,不知何故?
li_new 2003-09-01
  • 打赏
  • 举报
回复
支持这么热心的兄弟!
jscsqb 2003-09-01
  • 打赏
  • 举报
回复
to aloxy(亦杨)
ColdFusion->ASP
可以借用 hidden类型,通过表单提交
ColdFusion:
<cfset var1=1>
<cfform action="an.asp" method="post" name="form1">
<cfoutput>
<input type="hidden" name="var2" value= "#var1#">
</cfoutput>
</cfform>
那么在an.asp中可以通过request来提取var2的值,跟asp页互传数据时的接收是一样的。

aloxy 2003-08-31
  • 打赏
  • 举报
回复
有没有CF和asp互传的?
jscsqb 2003-08-31
  • 打赏
  • 举报
回复
有,这个相对简单一些。
等我忙完手中的工作给你写一个。

879

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 ColdFusion
社区管理员
  • ColdFusion社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧