ColdFusion如何从cfcatch获取消息

问题描述 投票:0回答:1

我正在上载cffile,并且想捕获MIME类型中的所有错误。我写了这段代码:

 <form 
 enctype= "multipart/form-data" 
 method = "post" 
 name   = "templupload"  
 action = "frag2.cfm">

<cftry>
   <cffile action = "upload"
    destination   = "#session.exploc#"
    fileField     = "form.theupload"
    mode          = '666'
    accept        = 'html'
    strict        = 'true'
    result        = 'ss'
    nameConflict  = "Overwrite">

    <!--- bad mime type files --->
    <cfcatch type = 'any'>   
       <cfif FindNoCase("The MIME type or the Extension of the uploaded file", cfcatch.message)>
       <cfoutput>
          <script>
             document.getElementById('tmpl').innerHTML = "error";
          </script>
       </cfoutput>   
       </cfif>
    </cfcatch>

 <cfthrow type="any" message="got an error" />         
</cftry>

[当我尝试上传错误的MIME类型时,它不会加载,这很好。表单正在提交,这不好,但是我稍后会处理。我现在的问题是我无法获得有关该错误的消息以显示在任何地方。我尝试了以下方法:

<cfcatch.message = 'error'; 
<script>alert('error');</script>
<script> document.getElementById('tmpl').innerHTML = "error";</script>
   <!--- this 2nd script does not work regardless of whether the tmpl
         id is on the original page or the target page --->  
<cfoutput> error </cfoutput>
<p> error </p>
<cfthrow type = 'any' message = 'error' />
<cfdump var = "#catch#"  or var = '#catch.message#"

我已经在cfcatch标记内外尝试了所有这些方法,但始终在cftry标记内。所有这些方法都在我所做的研究中,但没有一个对我有用。

谁能告诉我我在这里做错了吗?

coldfusion try-catch cfml
1个回答
2
投票

您是否正在寻找类似的东西?

 <cftry>

 <cfcatch>
      <cfset request.error = cfcatch.message>
 <cfcatch>

</cftry>

接着很多]

<cfif request.keyExists('error')>
    <cfoutput>#request.error#</cfoutput>
</cfif>
    
© www.soinside.com 2019 - 2024. All rights reserved.