本文介绍了是“POST请求参数的最大数量"吗?限制可捕获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Coldfusion 10 允许为 POST 请求参数的最大数量设置限制(服务器设置/设置/请求大小限制/POST 请求参数的最大数量).默认限制为 100.

是否可以在超出此限制时进行陷阱,以便可以使用自定义处理程序进行处理?如果可以,如何处理?

我尝试使用站点范围的错误处理程序和 Application.cfc 中的 onError() 方法来捕获它.两次尝试都没有成功.

感谢收看.

解决方案

我可以确认您所看到的行为.我认为在调用 Application.cfc 之前,CF servlet 抛出了异常,这可以解释为什么 onError 永远不会触发.

到目前为止,对我有用的唯一选择是 WEB-INFweb.xml 中添加自定义错误页面,使用 HTTP 状态码:

<错误代码>400</错误代码><location>/path/to/myErrorPage.cfm</location></错误页面>

注意:从评论中,@Adrian 提到他将上述内容添加到 cfusionuntimeconfweb.xml,而不是 web-inf 中的那个.

更新 1:

进一步阅读表明您还可以在更精细的级别上进行配置.要处理特定的某种异常,请使用 而不是 .例如:

<异常类型>java.lang.Exception</异常类型><location>/path/to/myErrorPage.cfm</location></错误页面>

更新 2:

原来 javax.servlet.ServletException 只是一个红鲱鱼.正如@AdrianWright 在评论中指出的那样,该错误与调试设置有关.当 CF 生成最大数量的 POST 请求参数"消息时,它没有正确考虑调试,进而导致 new 异常:java.lang.IllegalStateException.因此出现 HTTP 500 错误:

当调试被禁用时(就像在生产系统上那样),CF 只是将错误消息直接写入响应流并返回 HTTP 状态代码 400.由于没有抛出异常,; 在这里没用.所以你被困在使用状态码:

<错误代码>400</错误代码><location>/path/to/myErrorPage.cfm</location></错误页面>

但是,在自定义错误页面上,您可以提取错误消息来自请求流.然后进行相应处理:

 <cfset req = getPageContext().getRequest()><cfset 消息 = req.getAttribute("javax.servlet.error.message")><cfif 消息包含POST 参数超出">表单域太多.做一点事...<另类>其他一些原因.做别的事</cfif>

Coldfusion 10 allows a limit to be set for the maximum number of POST request parameters (Server Settings / Settings / Request Size Limits / Maximum number of POST request parameters). The default limit is 100.

Is it possible to trap when this limit has been exceeded so that it can be handled with a custom handler? If yes, how?

I've tried to trap it with a site wide error handler and an onError() method in Application.cfc. Neither attempt was successful.

Thanks for looking.

解决方案

I can confirm the behavior you are seeing. I think the exception is being thrown by the CF servlet, before Application.cfc is invoked, which would explain why onError never fires.

So far, the only option that worked for me is adding a custom error page in WEB-INFweb.xml, using an HTTP status code:

<error-page>
    <error-code>400</error-code>
    <location>/path/to/myErrorPage.cfm</location>
</error-page>

Note: From the comments, @Adrian mentioned that he added the above to cfusionuntimeconfweb.xml, rather than the one in web-inf.

Update 1:

Further reading suggests you can also configure things at a more granular level. To handle a specific kind of exception, use <exception-type> instead of <error-code>. For example:

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/path/to/myErrorPage.cfm</location>
</error-page>

Update 2:

Turns out the javax.servlet.ServletException was just a red herring. As @AdrianWright pointed out in the comments, that error is related to Debugging Settings. When CF generates the "Maximum number of POST request parameters" message, it does not properly account for debugging, which in turn causes a new exception: java.lang.IllegalStateException. Hence the HTTP 500 error:

When debugging is disabled (as it would be on a production system) CF simply writes an error message directly to the response stream and returns HTTP status code 400. Since no exception is thrown, <exception-type> is useless here. So you are stuck with using status code:

<error-page>
    <error-code>400</error-code>
    <location>/path/to/myErrorPage.cfm</location>
</error-page>

However, on the custom error page, you can extract the error message from the request stream. Then handle it accordingly:

  <cfset req = getPageContext().getRequest()>
  <cfset message = req.getAttribute("javax.servlet.error.message")>

  <cfif message contains "POST parameters exceeds">
     Too many form fields. do something...
  <cfelse>
     Some other cause. do something else
  </cfif>

这篇关于是“POST请求参数的最大数量"吗?限制可捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:04
查看更多