具有onError和cferror的ColdFusion问题

时间:2018-05-16 14:52:11

标签: javascript html server coldfusion

我遇到了一个问题,其中我的onError方法不再适用于我的application.cfc文件。程序正在捕获错误并昨天正确显示error.cfm,但现在我得到500错误。我的经理昨天可能已经在文件中更改了一些内容,但我们似乎已经重新创建了它并且没有修复任何内容。

我目前使用onError,但我尝试了cferror。有了cferror,数据输入表格甚至无法加载。

代码如下。 onError被阻止,因为我用cferror代码显示它。如果你想使用它,只需删除cferror和blocks将onError:

<!--- this component controls the application's global settings / event 
handlers and maintains user sessions --->
<cfcomponent>

  <!--- define some basic settings --->

  <cfset this.name = "QualityDataPortal" />
  <cfset this.sessionManagement = "yes" />
  <cfset this.setClientCookies = "no" />
  <cfset this.loginStorage = "session" />
  <!--- this function is triggered when our application is initialized --->
  <cffunction name="onApplicationStart" access="public" returntype="boolean" output="no">
    <!--- define application variables --->
    <cfset application.dataSource = 'quality' />
    <!--- return out --->
    <cfreturn true />
  </cffunction>
  <cferror
    template="error.cfm"
    type="exception"
    mailTo="Generic@org.edu" />
  <!--- <!--- this function is triggered when coldfusion encounters an error --->
    <cffunction name="onError" access="public" returntype="void" output="no">
      <cfargument name="exception" required="yes">
      <cfargument name="eventname" type="string" required="yes">

      <!--- send a dump of the error via email --->
      <cfmail from="QDP@org.edu" to="Generic@org.edu" subject="Quality Data Portal Error Encountered" type="html">
        <cfoutput>
          The following error was encountered on #dateformat(now(), 'dddd mmmm dd, yyyy')# at #timeformat(now(), 'hh:mm:ss tt')#<br /><br />
          <cfdump var="#arguments.exception#">
          <cftry><cfdump var="#arguments#"><cfcatch></cfcatch></cftry>
          <cfdump var="#form#">
          <cfdump var="#session#">
          <cfdump var="#cgi#">
        </cfoutput>
      </cfmail>

      <!--- alert the user that an error has been encountered --->
      <cflocation url="error.cfm" addtoken="no">
      <cfabort />

    </cffunction> --->

  <!--- this function is triggered when coldfusion receives a request for a template it cannot locate --->
  <cffunction name="onMissingTemplate" access="public" returntype="void" output="no">
    <cfargument name="targetPage" type="string" required="yes">
    <!--- alert the user that the page they requested could not be found --->
    <cflocation url="404.cfm" addtoken="no">
    <cfabort />
    <!--- return out --->
    <cfreturn />
  </cffunction>
</cfcomponent>

1 个答案:

答案 0 :(得分:1)

我建议,所以你可以看得更清楚,删除未使用的代码(cferror标签),删除不必要的注释,不要嵌套注释。

然后,从onError

的代码开始
<cffunction name="onError" returntype="void" output="false">

    <cfargument name="exception" required="true">
    <cfargument name="eventname" type="string" required="true">

    <cfmail to="Generic@org.edu" from="QDP@org.edu" subject="Quality Data Portal Error Encountered" type="html">

        <cfoutput>The following error was encountered on #DateFormat(now(), "dddd, mmmm dd, yyyy")# at #TimeFormat(now(), "HH:nn:ss")#</cfoutput>
        <hr />
        <cfdump var="#exception#" label="Exception" />        
        <cfdump var="#form#" label="Form" /> 
        <cfdump var="#session#" label="Session" /> 
        <cfdump var="#cgi#" label="CGI" /> 

    </cfmail>

    <cflocation url="error.cfm" addtoken="false" />

</cffunction>

注意:

  • 请注意:#timeformat(now(), 'hh:mm:ss tt'),它应该使用nn分钟而不是mm
  • <cflocation ...之后没有代码,因为ColdFusion不会运行它。
  

停止执行当前页面并打开ColdFusion页面或HTML文件。   (https://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7cac.html