在coldfusion中,变量在什么范围内可以传递给iframe页面? [英] in coldfusion, variables in what scope can be passed to and iframe page?

查看:116
本文介绍了在coldfusion中,变量在什么范围内可以传递给iframe页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了2页来测试这个问题,但服务器投诉错误。我不知道为什么,有人可以解释一下吗?非常感谢。



这是 1.cfm

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // EN
http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd\">
< html>
< head>
< meta http-equiv =Content-typecontent =text / html; charset = utf-8/>
< title>页面标题< / title>
< / head>
< body>
< cfscript>
a =aaaaaaaaaaa;
b =bbbbbbbbbbb;

request.r1 =rrrrrrr111111111;
request.r2 =rrrrrrrr222222222;

session.s1 =sssssssssss11111111111;
session.s2 =sssssssssss2222222222;
< / cfscript>
< iframe src =2.cfmwidth =600height =400name =myframescrolling =yes>
< / iframe>< br />
变量
< cfdump var =#variables#>
请求
< cfdump var =#request#>
session
< cfdump var =#session#>
< / body>
< / html>

这是 2.cfm

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // EN
http ://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
< html>
< head>
< meta http-equiv =Content-typecontent =text / html; charset = utf-8/>
< title> 2.cfm< / title>
< / head>
< body>
变量
< cfdump var =#variables#>
请求
< cfdump var =#request#>
session
< cfdump var =#session#>
< / body>
< / html>


解决方案

好像你误解了一个基本的概念网页请求。



iframe虽然显示为呈现页面的一部分,但实际上是它自己的请求,完全独立于原始页面请求。



会话变量将在两者之间共享(假设您在Application.cfm / Application.cfc中启用了会话),尽管您不太可能进入通过从父页面(1.cfm)设置变量并从iframe(2.cfm)中的子页面读取变量来竞争条件,这不是一个好主意(最佳实践)。



在父页面(1.cfm)中设置的请求变量将可用于iframe(2.cfm)中的页面,因为它是一个单独的请求。



就像请求范围对每个请求是私有的(但是对所有模板和对象共享),变量范围对每个模板都是私有的(bu)当使用cfinclude时,他们之间共享。)



虽然您的iframe可以访问自己的 请求变量范围,它们与原始页面的范围不同(1.cfm)。



这是一个相当基本的编程概念一般,也是ColdFusion。如果你发现很难掌握,你可以考虑购买一份ColdFusion Web应用程序构建工具包,它可以让你从完整的新手到初级中级水平相当快。


i wrote 2 pages to test this problem, but the server complaints error. i don't know why, anyone can explaint it? great thanks.

this is 1.cfm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Page Title</title>
    </head>
    <body>
        <cfscript>
            a="aaaaaaaaaaa";
            b="bbbbbbbbbbb";

            request.r1="rrrrrrr111111111";
            request.r2="rrrrrrrr222222222";

            session.s1="sssssssssss11111111111";
            session.s2="sssssssssss2222222222";
        </cfscript>
        <iframe src="2.cfm" width="600" height="400" name="myframe" scrolling="yes">
        </iframe><br />
        variables
        <cfdump var="#variables#">
        request
        <cfdump var="#request#">
        session
        <cfdump var="#session#">
    </body>
</html>

and this is 2.cfm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>2.cfm</title>
    </head>
    <body>
        variables
        <cfdump var="#variables#">
        request
        <cfdump var="#request#">
        session
        <cfdump var="#session#">
    </body>
</html>

解决方案

It seems like you're misunderstanding a basic concept of web-page requests.

An iframe, while displayed as a portion of the rendering page, is in fact its own request, entirely separate from the original page request.

Session variables would be shared between the two of them (assuming you have sessions enabled in Application.cfm/Application.cfc), and although it's unlikely that you'll get into a race condition by setting variables from a parent page (1.cfm) and reading them from a child page in an iframe (2.cfm), it's just not a great idea (best practice).

Request variables set in the parent page (1.cfm) will not be available to the page in the iframe (2.cfm), as it is a separate request.

Like the Request scope is private to each request (but shared to all templates and objects), the "variables" scope is private to each template (but shared among them when using cfinclude).

While your iframe will have access to its own request and variables scopes, they will not be the same scope as the original page (1.cfm).

This is a fairly basic concept of programming in general, and also of ColdFusion. If you're finding it difficult to grasp, you might consider picking up a copy of the ColdFusion Web Application Construction Kit, which can take you from complete novice to beginner-intermediate level fairly quickly.

这篇关于在coldfusion中,变量在什么范围内可以传递给iframe页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆