如何从 ColdFusion 9 中的单独应用程序访问一个应用程序范围?
我对这个问题有自己的答案,我将发布该答案,但我想看看我是否错过了一个更简单的方法。我有两个应用程序在同一台 Coldfusion 服务器上运行,我想从另一个应用程序访问一个应用程序的范围。我该怎么做?
更新:
阅读@Daniel 和@Ben 的答案后,我回去从子应用程序的角度解决了我的问题,结果证明这是对我最初问题的更好解决方案。我的答案仍然是访问其他应用程序范围的“快速而肮脏”的方式,但将数据放入服务器范围是更好的做法。
I have my own answer to this question, which I'll post, but I wanted to see if I missed a simpler way. I have two application's running on the same coldfusion server, and I want to access the application scope of one from the other. How might I do this?
UPDATE:
After Reading @Daniel and @Ben's answers, I went back and approached my problem from the standpoint of sub-applications which turned out to be a better solution to my initial problem. My answer is still the "quick and dirty" way to access other application scopes, but putting data in the server scope is a better practice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你可能应该考虑一下为什么你想要这样做......从架构上来说,这似乎不太合理,即使它是可能的。对于您想要跨应用程序共享的资源,服务器范围会更好。
您甚至可能需要考虑这两个应用程序实际上是否应该是一个具有两个小型子应用程序的应用程序。
I think you should probably think about why it is that you want to do this... Architecturally this doesn't seem very sound, even if it is possible. The Server scope would be better for resources that you want to share across applications.
You might even want to consider whether the two applications should actually be one single application with two small sub-applications.
我从两个来源整理了我的答案。首先,Ben Nadel 对 ColdFusion PageContext 对象的大规模探索 (谢谢本)。其次,ColdFusion 帮助页面 与 JSP 页面和 servlet 进行互操作。将两者放在一起,我得到这个:
目录结构:
App1/Application.cfc:
App2/Application.cfc:
App2/index.cfm
在点击App1目录中的index.cfm后,您可以看到转储到的app1中的应用程序范围app2 的索引。
I put my answer together from two sources. First, Ben Nadel's Massive Exploration of the ColdFusion PageContext object (Thanks Ben). Second, the ColdFusion help page on Interoperating with JSP pages and servlets. Put the two together and I get this:
Directory structure:
App1/Application.cfc:
App2/Application.cfc:
App2/index.cfm
After hitting the index.cfm in the App1 directory, you can see the application scope from app1 dumped in the index of app2.
我完全同意@Daniel 关于架构的观点。
@Ryan 的回答很好。
我想我会提供我想到的替代方案,它有一些优点,也有一些缺点。
基本上,应用程序之间共享的任何数据都可以写入服务器范围。例如:
优点:
缺点
无论如何,这是我的第一个想法,但在阅读了 @Ryan 的答案后,我可能会编写一个采用应用程序名称和 var 名称的 UDF,并将其用作他所做的事情的外观。
但认真地考虑一下,跨应用程序共享数据是否比合并它们更聪明/明智。
I completely agree with @Daniel about the architecture.
@Ryan's answer is a good one.
I thought I would offer the alternative I thought of, which has a few advantages, and a few drawbacks.
Basically, any data to be shared between the apps can be written to the server scope. For example:
Advantages:
Disadvantages
Anyway, this was my first thought but after reading @Ryan's answer, I'd probaly just write a UDF that takes an application name and a var name, and use it as a facade for what he did.
But seriously, consider whether sharing data across appications is smarter/wiser than merging them.
ColdFusion 应用程序范围由 ApplicationScopeTracker java 类处理。
您可以访问另一个应用程序的应用程序范围。
它没有记录,我不会在生产中使用它!
假设您有 2 个网络应用,名称分别为
app1
和app2
。在
app1
上运行此命令以访问app2
的应用程序范围:如果
app2
应用程序尚未启动或超时,则getApplicationScope ()
将返回未定义。您还可以使用
appTracker.getApplicationKeys()
获取所有当前应用程序范围的枚举ColdFusion application scopes are handled by the ApplicationScopeTracker java class.
You can access an application scope of another app.
It's undocumented and I wouldn't use it for anything in production!
Lets say you have 2 web apps with the names
app1
andapp2
.Run this on
app1
to accessapp2
's application scope:If the
app2
application has not started, or has timed out,getApplicationScope()
will return undefined.You can also get an enumeration of all current application scopes using
appTracker.getApplicationKeys()