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

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

问题描述

我试图使用JSoup与ColdFusion清理一些HTML,但遇到以下错误:


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))>

我已经转储了白名单对象,并且添加标签方法存在。如果我删除addTags()方法并使用标准的JSoup白名单,如basic(),none()或relaxed(),那么代码运行完美。就我从其他在线示例中可以看到这是使用addTags()方法的正确语法。



在ColdFusion中使用Java对象是相当新的,所以这个



感谢,
Michael。非常感谢。

解决方案

addTags 方法需要一个字符串数组,单字符串。首先将值放入数组:

 <!---创建一个CF数组,然后将其转换为string [ ---> 
< cfset tagArray = javacast(string [],[span])>
< cfset post = jsoup.clean(post,Whitelist.none()。addTags(tagArray))>



编辑


至于其他在线示例,这是正确的
语法


澄清,正确的语法 - 对于java。在Java中,您可以传递可变参数个数< a>使用数组或以下语法: addTags(tag1,tag2,...)。但是,CF仅支持数组语法。所以如果你cfdump的java对象,你会看到方括号后的类名,这表明参数是一个数组:

 方法:addTags(java.lang.String [])//字符串数组


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

The addTags method was not found. Either there are no methods with the specified method name and argument types or the addTags method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

My code is as follows:

<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"))>

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.

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

Any help would be greatly appreciated.

Thanks, Michael.

解决方案

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 ))>

Edit:

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

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天全站免登陆