我在ColdFusion和JSON方面遇到了一些问题.我的用户有文件名和其他关键字ç,其中包含像我们这样的字符,当我必须通过JSON传回它们时,这会让我感到痛苦.
当我在我的变量上使用魔术JSON命令时:
<cfcontent type="application/json">
<cfset variables.stGalleryItem = StructNew() />
<cfset variables.stGalleryItem["imagePath"] = siteRoot & '/images/350460/hellç.txt' />
<cfset variables.stGalleryItem["title"] = 'çççç' />
<cfset variables.stGalleryItem["author"] = 'HI' />
<cfset variables.stGalleryItem["text"] = 'aa' />
<cfset ArrayAppend(variables.arrGallery,variables.stGalleryItem) />
<cfoutput>
#Trim(SerializeJSON(variables.arrGallery))#
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
吐出的角色是 ,没有任何好处.
有什么我可以做的来保护我的用户ç吗?
例如,如果我有一个类似<cf_AppSwitch action="Check">我的假设的自定义标签AppSwitch(action="Check"),但我不确定CF可以将其解析为自定义标签.
我能想到的另一个解决方案是编写一个包装函数并调用我的自定义标记,但这感觉多余.
似乎我过于简单化了一个更复杂的问题,所以任何见解都会受到赞赏(甚至为什么不支持/不应该支持).
当试图做EntitySave("publications",arguments);...我收到以下错误.
ids for this class must be manually assigned before calling save(): publications
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么..我的数据库主键设置正确,我在我的CFC中有setter = false这些属性.我在谷歌搜索时发现了这个错误,但似乎没有任何迹象表明这是导致我的问题的原因.
这是我的CFC.关于我可能做错的任何指示都表示赞赏.谢谢你提前!
Publications.cfc
component persistent="true" table="publications"
hint="Publications"{
property name="id" fieldtype="id" setter="false";
property name="typeid" omrtype="int";
property name="name" ormtype="string";
property name="dateScheduled" ormtype="date" ;
property name="tstamp" ormtype="date";
property name="Article" fieldtype="one-to-many" cfc="publicationArticles" fkcolumn="publicationid";
}
Run Code Online (Sandbox Code Playgroud)
publicationArticles.cfc
component persistent="true" table="publicationArticles"
hint="Publications"{
property name="id" fieldtype="id" setter="false" ;
property name="typeid" ormtype="int";
property name="title" ormtype="string" ;
property name="status" ormtype="boolean";
property name="publication" fieldtype="many-to-one" cfc="publications" fkcolumn="publicationid" ;
}
Run Code Online (Sandbox Code Playgroud)
publicationTypes.cfc
component persistent="true" table="publicationTypes"
hint="Publicatin Type …Run Code Online (Sandbox Code Playgroud) 我正在寻找从cfscript中的不同组件动态调用方法的最佳方法.请注意,它涉及不同组件中的方法.到目前为止,我已经尝试了3种不同的方法,但它们似乎都不是我正在寻找的:
所有案例都是在组件方法中的cfscript中编写的.假设我正在尝试动态调用MyComponent组件中的setName(required string name)方法.所有案例都定义了以下变量:
var myComp = new MyComponent();
var myMethod = "setName";
var args = {"name"="foo"};
Run Code Online (Sandbox Code Playgroud)
使用evaluate()作业
evaluate("myComp.#myMethod#(argumentCollection=args)");
Run Code Online (Sandbox Code Playgroud)
专业人士:使用非常少的代码
缺点:代码不是很"干净",使用evaluate()似乎在在线社区中具有"邪恶"的声誉.我不希望我的代码变得邪恶.
使用cfml包装器 <cfinvoke>
invoke("MyComponent", myMethod, args);
Run Code Online (Sandbox Code Playgroud)
专业人士:我可以使用cfinvoke
cons的所有功能:它为MyComponent每次调用创建一个新实例.
dynamicMethod在MyComponent中创建一个方法
myComp.dynamicMethod(myMethod, args);
Run Code Online (Sandbox Code Playgroud)
myComponent的dynamicMethod:
public any function dynamicMethod(required string methodName, required struct argumentColl){
var cfcMethod = variables[arguments.methodName];
return cfcMethod(argumentCollection=arguments.argumentColl);
}
Run Code Online (Sandbox Code Playgroud)
专业人士:我终于可以直接调用myComp了.迄今为止最舒适的解决方案
缺点:我现在可以通过dynamicMethod调用MyComponent的私有方法.
(我还尝试了MyComponent之外的'function as variable'解决方案,但是函数失去了它的工作上下文.例如,如果MyComponent扩展了一个组件,'super'范围将不再引用扩展组件).
这些解决方案似乎都不是完美的,所以没有其他方法可以从不同的控制器调用动态函数吗?
如果没有,哪一个是最佳解决方案?
欢迎任何建议,谢谢.
我试图将以下字符串插入sql xml字段
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Ip>x.x.x.x</Ip>
<CountryCode>CA</CountryCode>
<CountryName>Canada</CountryName>
<RegionCode>QC</RegionCode>
<RegionName>Québec</RegionName>
<City>Dorval</City>
<ZipCode>h9p1j3</ZipCode>
<Latitude>45.45000076293945</Latitude>
<Longitude>-73.75</Longitude>
<MetroCode></MetroCode>
<AreaCode></AreaCode>
</Response>
Run Code Online (Sandbox Code Playgroud)
插入代码如下所示:
INSERT
INTO Traffic(... , xmlGeoLocation, ...)
VALUES (
...
<!---
<cfqueryparam CFSQLType="cf_sql_varchar" value="#xmlGeoLocation#">,
--->
'#xmlGeoLocation#',
...
)
Run Code Online (Sandbox Code Playgroud)
发生了两件坏事:
魁北克变成了Québec
我收到一个错误说 [Macromedia][SQLServer JDBC Driver][SQLServer]XML parsing: line 8, character 16, illegal xml character
更新:
传入的测试流主要是单字节字符.
é是一个双字节字符.特别是C3A9
此外,我无法控制传入的xml流
我正在使用ChromeLogger扩展程序(无耻插件)的CF接口,它使用HTTP标头将数据从服务器端语言记录到Chrome控制台.
在请求过程中,log()可以多次调用该方法.对于每次通话,我都会以ChromeLogger正确显示数据所需的格式编写标题.在CF10中,这很好 - 每次后续调用都会setHeader()覆盖以前设置的标题,并使用相同的名称.但是,在CF9中,我看到多个具有相同名称的标头.
此示例代码演示了此问题:
<cfscript>
pc = getPageContext().getResponse();
pc.setHeader( "test-header", "value 1" );
pc.setHeader( "test-header", "value 2" );
pc.setHeader( "test-header", "value 3" );
</cfscript>
Run Code Online (Sandbox Code Playgroud)
在CF9中,我看到三个名为"test-header"的标题,每个标题都有自己的值.在CF10中,我看到一个名为"test-header"的标题,其值为"value 3".根据这个方法的Java文档,后者是正确的(强调我的):
设置具有给定名称和值的响应标头.如果已设置标头,则新值将覆盖前一个标头.containsHeader方法可用于在设置其值之前测试标头的存在.
使用cfheader标签具有相同的结果,大概是因为它只是包装了setHeader()方法.
我知道我可以在请求过程中构建标题,然后setHeader()在最后通过一次调用onRequestEnd(),但我希望这个组件尽可能自包含 - 最终用户越少修改他们的代码来实现它,越多越好.
CF9中有没有其他方法可以覆盖现有的标题?
编辑3:感谢@Leigh的帮助我将问题缩小到了查询中的日期列.使用原始代码集和POI时,当SpreadSheetAddRows()尝试添加包含类似日期的单元格的非常大的查询时,页面崩溃.我在这里做了一个错误报告:https://bugbase.adobe.com/index.cfm?event = bug &id = 3432184.
我有一个查询,我添加到一个spreadhseet对象,当查询具有非常多的行(在此示例中为18583)时似乎出错.确切的错误如下:
java.lang.ArrayIndexOutOfBoundsException: -32735
at java.util.ArrayList.get(ArrayList.java:324)
at org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.j ava:50)
at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:787)
at org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle(HSSFCell.java:901 )
at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java :1727)
at coldfusion.excel.Excel.autoResize(Excel.java:1246)
at coldfusion.excel.Excel.autoResize(Excel.java:1240)
at coldfusion.excel.Excel.addRows(Excel.java:1214)
at coldfusion.runtime.CFPage.SpreadSheetAddRows(CFPage.java:7089) at coldfusion.runtime.CFPage.SpreadSheetAddRows(CFPage.java:7076)
Run Code Online (Sandbox Code Playgroud)
这是相关的代码:
<cfset xls = spreadsheetNew()>
<cfset spreadsheetAddRow(xls, arrayToList( qryTest.getMeta().getColumnLabels() ))>
<cfset SpreadsheetFormatRow(xls, {bold=true,fgcolor="brown",color="white"}, 1)>
<cfset SpreadsheetAddRows(xls, qryTest)>
<cfheader name="Content-Disposition" value="attachment; filename=#filename#">
<cfcontent variable="#spreadsheetReadBinary(xls)#" reset="yes" type="application/vnd.ms-excel">
Run Code Online (Sandbox Code Playgroud)
编辑:我之前成功使用过cfspreadsheet,但它没有生成带有标题的电子表格(并且它还有需要创建临时文件以供服务的缺点.)
EDIT2:关注@Leigh建议我更新了CF9/lib文件夹中的POI.现在错误已更改为以下内容:
<cfset SpreadsheetFormatRow(xls, {bold=true,fgcolor="brown",color="white"}, 1)> 给出以下消息:org.apache.poi.hssf.util.HSSFColor.getIndexHash()Ljava/util/Hashtable;
错误代码:
java.lang.NoSuchMethodError:
org.apache.poi.hssf.util.HSSFColor.getIndexHash()Ljava/util/Hashtable;
at coldfusion.excel.Excel.getHSSFColor(Excel.java:2094)
at coldfusion.excel.Excel.findFont(Excel.java:2237)
at coldfusion.excel.Excel.getCellStyle(Excel.java:2318)
at coldfusion.excel.Excel.formatRow(Excel.java:2948)
at …Run Code Online (Sandbox Code Playgroud) 为什么以下工作在CF10而不是CF9?
<cfset out="">
<cfif isQuery( arguments.values ) >
<cfloop query="#arguments.values#" >
<cfset out = '#out#<option value="#value#">#label#</option>'>
</cfloop>
</cfif>
Run Code Online (Sandbox Code Playgroud)
CF9声明"复杂对象类型无法转换为简单值".对于包含cfloop的行.我正在使用Coldbox框架,它的调试器信息显示arguments.values是一个带有Label&Value列的查询.
今天在修复一些现有代码中的错误时,我发现了一个奇怪的错误.
分支目标偏移量太大
搜索后我发现它与Java字节码转换有关.以下是我发现的链接:
在我的情况下,cftransaction包含大约870个语句,它工作正常.但我需要在此事务中再添加2个查询.现在,当我在cftransaction中添加一行代码时,我收到此错误.目前我无法将任何现有的cfquery移出cftransaction.
以下是代码的整体结构:
<cftransaction action="begin">
<cfif URL.action eq 'add'>
Around 200 lines of queries/statements
<cfelseif URL.action eq 'edit'>
Around 200 lines of queries/statements
</cfif>
<cfif URL.action eq 'add' or URL.action 'edit'>
Around 450 lines of queries/statements
</cfif>
</cftransaction>
Run Code Online (Sandbox Code Playgroud)
有没有解决此问题的解决方法?
我使用ColdFusion导出相当少的行(大约1000)但是大量的列(大约300)到Excel.它是一个多页Excel文件,其中至少有两个页面具有大量列.使用cfspreadsheet抛出Java堆错误.更新JVM设置值没有显示任何改进.在不导致Java堆错误的情况下导出到Excel的最佳方法是什么?
编辑:我已经尝试了几种方法来解决程序中的问题.我正在使用cfsavecontent中的xml工作簿来构建多个工作表并使用cfcontent呈现结果.在这种情况下,cfcontent可能会使用大量内存,从而导致堆空间错误.
<cfsavecontent variables="REQUEST.xmlData">
<cfoutput>
<xml version="1.0"?>
<?mso-application progid="Excel.sheet"?>
<Workbook>
...other contents
</Workbook>
</cfoutput>
</cfsavecontent>
Run Code Online (Sandbox Code Playgroud)
对于第二种解决方法,我使用querynew来构建内容并使用在Excel中转储最终结果<Cfspreadsheet action="write">.对于后续的工作表,我正在使用<cfspreadsheet action="update">.最终目标是使用excel <cflocation url="excelPath">,但在这种情况下,cfspreadsheet更新将永远丢失内存错误.
如果更新jvm不是一个选项,那么您建议采用哪些其他方法来克服内存问题.
coldfusion ×10
coldfusion-9 ×10
apache-poi ×1
arrays ×1
cfquery ×1
chromelogger ×1
excel ×1
java ×1
json ×1
sql-server ×1
xml-parsing ×1