在ColdFusion中安全地调用String上的底层java方法? [英] Safe to call underlying java method on String in ColdFusion?

查看:146
本文介绍了在ColdFusion中安全地调用String上的底层java方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Adob​​e ColdFusion是基于Java构建的。 CFML / CFSCRIPT中的几乎所有简单变量都是 java.lang.String ,直到操作需要它是某种类型。

Adobe ColdFusion is built on Java. Almost all simple variables in CFML/CFSCRIPT are java.lang.String until the operation needs it to be of a certain type.

我一直想在 String 中使用 startsWith(),而不是更大的CFML变体。

I've always want to use startsWith() in String instead of the more bulky CFML variant.

left(str,4) EQ "test"

但是,在ColdFusion中使用底层Java方法的一般共识是什么?

However, what's the general consensus of using underlying Java method in ColdFusion?

c $ c> javacast() var first?

Would this be any safer to javacast() the var first?

javacast("String",x).startsWith("test");

如果CF引擎不是在Java之上构建的,该怎么办?

What if the CF engine is not built on top of Java?

感谢

推荐答案

是的,您可以使用Adobe ColdFusion和其他CFML引擎Java。

Yes, you can do this with Adobe ColdFusion and other CFML engines that are built on Java. It's actually simpler than you thought.

<cfset str = "hello what's up" />
#str.startsWith("hello")# <!--- returns "YES" --->
<cfif str.startsWith("h")>
  This text will be output
</cfif>

#str.startsWith("goodbye")# <!--- returns "NO" --->
<cfif str.startsWith("g")>
  This text will NOT be output
</cfif>

这是可能的,因为ColdFusion中的CFML字符串与Java字符串相同。您可以使用任何本地字符串方法(Java.lang。

This is possible because CFML strings in ColdFusion are the same as Java strings. You can use any native string method (Java.lang.String) on a CFML string.

如果你没有猜到,这也适用于CFML数组(某种类型的列表,可能是一个java.util .Vector)和structs(可能是一个java.util.Map)。

If you haven't guessed, this also works with CFML arrays (some kind of list, probably a java.util.Vector) and structs (probably a java.util.Map). Experiment with data types and the cfdump tag, you will find a lot of secrets.

一个警告,这是标准CFML,所以如果你的底层引擎改变,包括只是升级到一个新版本,它不能保证它仍然可以工作。

One word of warning, this is not standard CFML, so if your underlying engine changes, including just upgrading to a new version, there are no guarantees that it will still work.

这就是说,string.startsWith到Java和.NET,所以如果你的CFML引擎是BlueDragon.NET,这也将工作。只有ColdFusion 5和以前版本不能使用的CFML引擎。

That said, string.startsWith() is native to Java as well as .NET, so this will also work if your CFML engine is BlueDragon.NET. The only CFML engines it will not work on are ColdFusion 5 and previous.

使用它是否安全?我会说是的。只要CFML引擎运行在Java或.NET上,它就完全安全。它是没有文件,但很容易理解,所以我会说使用它自由。

Is it safe to use? I would say yes. As long as CFML engines run on Java or .NET, it's perfectly safe. It's undocumented, but easy to understand, so I would say use it freely.

这篇关于在ColdFusion中安全地调用String上的底层java方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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