ColdFusion 和 JSoup - 找不到 addTags 方法错误 [英] ColdFusion and JSoup - The addTags method was not found error

查看:30
本文介绍了ColdFusion 和 JSoup - 找不到 addTags 方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JSoup 和 ColdFusion 来清理一些 HTML,但遇到以下错误:

I am trying to use JSoup with ColdFusion to clean up some HTML but am encountering the following error:

找不到 addTags 方法.要么没有具有指定方法名称和参数类型的方法,要么 addTags 方法被 ColdFusion 无法可靠破译的参数类型重载.ColdFusion 找到 0 个与提供的参数匹配的方法.如果这是一个 Java 对象并且您验证了该方法存在,请使用 javacast 函数来减少歧义.

我的代码如下:

<cfset jsoup = createObject('java','org.jsoup.Jsoup')>
<cfset Whitelist = createObject("java", "org.jsoup.safety.Whitelist")>

<cfset parsedhtml = jsoup.parse(form.contentrichtext)> 
<cfset post = parsedhtml.body().html()>
<cfset post = jsoup.clean(post, Whitelist.none().addTags("span"))>

我已经转储了 Whitelist 对象,并且存在 add Tags 方法.如果我删除 addTags() 方法并使用标准 JSoup 白名单之一,例如 basic()、none() 或 Relax(),则代码运行完美.据我从其他在线示例中可以看出,这是使用 addTags() 方法的正确语法.

I have dumped out the Whitelist object and the add Tags method is present. If I remove the addTags() method and use one of the standard JSoup Whitelists such as basic(), none() or relaxed() then the code runs perfectly. As far as I can see from other online examples this is the correct syntax for using the addTags() method.

我对在 ColdFusion 中使用 Java 对象还很陌生,所以这让我很困惑.

I am fairly new to using Java objects within ColdFusion so this has got me stumped.

任何帮助将不胜感激.

谢谢,迈克尔.

推荐答案

addTags 方法需要一个字符串数组,而不仅仅是一个字符串.先将值放入数组中:

The addTags method expects an array of strings, not just a single string. Put the value into an array first:

<!--- create a CF array then cast it as type string[] --->  
<cfset tagArray = javacast("string[]", ["span"]) >
<cfset post = jsoup.clean(post, Whitelist.none().addTags( tagArray ))>

据我从其他在线示例中可以看出,这是正确的语法

As far as I can see from other online examples this is the correct syntax

为了澄清,正确的语法 - 对于java.在 java 中,您可以传入 可变数量的参数 使用数组或以下语法:addTags("tag1", "tag2", ...).但是,CF 只支持数组语法.所以如果你cfdump这个java对象,你会在类名后面看到方括号,表示参数是一个数组:

To clarify, that is the correct syntax - for java. In java you can pass in a variable number of arguments using either an array or this syntax: addTags("tag1", "tag2", ...). However, CF only supports the array syntax. So if you cfdump the java object, you will see square brackets after the class name, which indicates the argument is an array:

     method:  addTags( java.lang.String[] )  // array of strings

这篇关于ColdFusion 和 JSoup - 找不到 addTags 方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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