0

我有一个页面,它从会话变量(session.stufailedarray)将包含一些信息的数组打印到屏幕上。在页面顶部,有一个将信息导出到 Excel 的链接。当我尝试这个(在 Firefox、IE 和 Chrome 中)时,它工作正常。但是用户一直告诉我他们收到一条错误消息:“元素 stufailarray 未定义是会话”。我知道变量在那里,因为它只是将它打印到屏幕上,我可以在调试中看到它。为什么会发生这种情况,而且只是有时?

产生错误的代码:

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

2 回答 2

1

根据您的问题,您有一个名为session.stufailedarray. 但是,在您发布的代码(生成错误)中,您拥有session.stufailarray. 这也是您收到的错误消息。

"Element stufailarray is undefined is session"

请注意,设置(可用)变量,失败是传递时态,错误变量是现在时态。

于 2013-10-15T07:52:26.260 回答
1

试试这个:

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

确保您正确配置和启用了应用程序会话。要使用会话变量,请在两个地方启用它们:

ColdFusion 管理员 Application.cfc 初始化代码 This.sessionManagement 变量或活动 cfapplication 标签。ColdFusion Administrator、Application.cfc 和 cfapplication 标记还提供用于配置会话变量行为的工具,包括变量超时。

配置和使用会话变量

于 2013-07-19T12:09:02.797 回答