ColdFusion and JSoup - The addTags method was not found error

后端 未结 1 800
北海茫月
北海茫月 2021-01-19 09:29

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 t

相关标签:
1条回答
  • 2021-01-19 09:41

    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
    
    0 讨论(0)
提交回复
热议问题