会话中未定义coldfusion 9变量
我有一个页面,可以从会话变量(session.stufailedarray)将包含一些信息的数组打印到屏幕上。在页面顶部,有一个将信息导出到excel的链接。当我尝试这个(在Firefox、IE和Chrome中)时,效果很好。但用户不断告诉我,他们收到了一条错误消息:“数组未定义的元素是会话”。我知道变量在那里,因为它只是将它打印到屏幕上,我可以在调试中看到它。为什么会发生这种情况,而且只是偶尔发生 生成错误的代码:会话中未定义coldfusion 9变量,coldfusion,undefined,coldfusion-9,Coldfusion,Undefined,Coldfusion 9,我有一个页面,可以从会话变量(session.stufailedarray)将包含一些信息的数组打印到屏幕上。在页面顶部,有一个将信息导出到excel的链接。当我尝试这个(在Firefox、IE和Chrome中)时,效果很好。但用户不断告诉我,他们收到了一条错误消息:“数组未定义的元素是会话”。我知道变量在那里,因为它只是将它打印到屏幕上,我可以在调试中看到它。为什么会发生这种情况,而且只是偶尔发生 生成错误的代码: <cfset ind=0> <cfset anArray=a
<cfset ind=0>
<cfset anArray=arrayNew(2)>
<cfloop array="#session.stufailarray#" index="k">
<cfset ind+=1>
<cfset session.failed=find("UPDATE FAILED: ", "#k#")>
<cfset session.rrr=REFind("\d{9,9}", "#k#")>
<cfset idno=mid("#k#", REFind("\d{9,9}", "#k#"), 9)>
<cfset failed=mid("#k#", Refind("UPDATE FAILED: ", "#k#"), Len(#k#)-(Refind("UPDATE FAILED: ", "#k#")))>
<cfset anArray[ind][1]=#idno#>
<cfset anArray[ind][2]=#failed#>
</cfloop>
<!--- Set content type. --->
<cfcontent type="Application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="filename=load_status.xls">
<cfoutput>
<table cols=2 border=1>
<cfloop from="1" to ="#ArrayLen(anArray)#" index="row">
<tr>
<td>#anArray[row][1]#</td>
<td>#anArray[row][2]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
#阿纳雷[世界其他地区][1]#
#阿纳雷[世界其他地区][2]#
试试这个:
<!--- Set content type. --->
<cfset anArray=[]/>
<cfif isDefined(session.stufailedarray)>
<cfset anArray=session.stufailedarray/>
</cfif>
<cfcontent type="Application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="filename=load_status.xls">
<cfoutput>
<table cols=2 border=1>
<cfloop from="1" to ="#ArrayLen(anArray)#" index="row">
<tr>
<td>#anArray[row][1]#</td>
<td>#anArray[row][2]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
#阿纳雷[世界其他地区][1]#
#阿纳雷[世界其他地区][2]#
确保正确配置和启用了应用程序会话。
要使用会话变量,请在两个位置启用它们:
ColdFusion管理员输入Application.cfc初始化代码
This.sessionManagement变量或活动cfapplication标记。
ColdFusion管理员、Application.cfc和cfapplication标记
还提供配置会话变量行为的工具,
包括可变超时
根据您的问题,您有一个名为
session.stufailedarray
的变量。但是,在您发布的代码(生成错误)中,您有session.stufailarray
。这也是您收到的错误消息
"Element stufailarray is undefined is session"
请注意,set(available)变量failed是pass时态,而error变量是现在时态。我看不出该代码引用了
session。stufailedarray
这可以防止出错,但不能解决session变量未定义的问题。我同意,我们需要更多详细信息。