Adobe ColdFusion 8

cfabort

描述

在这个标签的位置中止这个正在执行的Coldfuion页面. Coldfuion会传回在这个标签之前执行的结果.这个标签主要用于中止执行一个网页内的条件判断逻辑内.

类别

流程控制 标签

语法

<cfabort 
    showError = "error message">

注: 你可以在attributeCollection 中指定这个标签的属性,作为一个结构的value,在attributeCollection 中指定结构的名称,并使用这个标签的属性名称作为这个结构的Keys.

查看更多

cfbreak, cfexecute, cfexit, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry; "cfabort and cfexit" ColdFusion 开发者指南

属性

属性

必须/可选

默认

描述

showError

可选

 

自定错误信息显示, 当这个标签配合这个属性执行时,要显示的错误信息,这些错误信息是定义在标准的ColdFusion error页面内.

用途

cfabortcferror一起使用时,cfabort会立即中止这个处理; cferror会将执行的结果重新导向到另一个指定页面上.

如果这个标签不包含showError属性值,会立即停止网页继续向下执行,并传回<cfabort>这个标签之前的执行结果.

当你使用标签的showError属性,但未使用cferror定义一个错误页面时,页面一执行到cfabort,页面的访问立即停止.这个错误信息透过showError在客户端显示出来.

当你将showErrorcferror同时使用的时候,ColdFusion会将错误信息重新导向到cferror所指定的错误讯息中.

范例

以下范例展示使用cfabort中止页面执行操作.在第二个范例中,cfabort被使用的位置,错误信息不会再被显示出来.

<h3>Example A: Let the instruction complete itself</h3>
<!--- first, set a variable --->
<cfset myVariable = 3>
<!--- now, perform a loop that increments this value --->
<cfloop from = "1" to = "4" index = "Counter">
    <cfset myVariable = myVariable + 1>
</cfloop>

<cfoutput>
<p>The value of myVariable after incrementing through the loop #Counter# times is:
    #myVariable#</p>
</cfoutput>

<h3>Example B: Use cfabort to halt the instructions with showmessage attribute and
    cferror</h3>
<!--- Reset the variable and show the use of cfabort. --->
<cfset myVariable = 3>
<!--- Now, perform a loop that increments this value. --->
<cfloop from = "1" to = "4" index = "Counter">
<!--- On the second time through the loop, cfabort. --->
    <cfif Counter is 2>
    <!--- Take out the cferror line to see cfabort error processed by CF error page. --->
        <cferror type="request" template="request_err.cfm">
        <cfabort showerror="CFABORT has been called for no good reason">
<!--- Processing is stopped, --->
<!--- and subsequent operations are not carried out.--->
    <cfelse>
        <cfset myVariable = myVariable + 1>
    </cfif> 
</cfloop>

<cfoutput>
<p> The value of myVariable after incrementing through the loop#counter# times is: #myVariable#</p>
</cfoutput>