tomcat8-400的自定义错误页面 [英] tomcat8 - custom error page for 400

查看:312
本文介绍了tomcat8-400的自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Tomcat(v8.5.24)中,带有查询参数的URL包含未编码的花括号("{"),会产生400错误.

In Tomcat (v8.5.24) an URL with a query parameter containing an unencode curly brace ("{") produces a 400 error.

您可以配置Tomcat以使其带有"relaxedQueryChars".但这不是我想要的.我试图编写一个自定义错误页面并将其添加到web.xml

You can configure Tomcat to allow it with "relaxedQueryChars". But this is not what I want. I tried to write a custom error page and add it to web.xml

<error-page>
        <error-code>400</error-code>
        <location>/error/error400</location>
</error-page>

但是这不起作用,因为Tomcat确实终止了请求并且不处理错误页面(org.apache.coyote.http11.Http11Processor:737)

But this does not work as Tomcat is really killing the request and does not process the error pages (org.apache.coyote.http11.Http11Processor:737)

似乎没有办法处理它.现在,我尝试在Nginx中处理它.但是要在那里处理,我需要设置"proxy_intercept_errors = on",并且我不想拦截代理中的所有错误代码.

It seems there is no way to handle it. Now I tried to handle it in nginx. But to handle it there I need to set "proxy_intercept_errors = on" and I don't want to intercept all error codes from my proxy.

那么在这种情况下渲染一个自定义400页的运气没有?还是有任何解决方法?

So no luck rendering a custom 400 page in this scenario? Or is there any workaround?

推荐答案

我也遇到了这个问题,作为解决方法,我通过扩展org.apache.catalina.valves.ErrorReportValve类并在Tomcat上对其进行了配置,实现了自己的ErrorReportValve.

I also faced to this issue and as a workaround I implemented own ErrorReportValve by extending org.apache.catalina.valves.ErrorReportValve class and configured it on my Tomcat.

为完成此任务,以下文章非常有帮助: http://robupcraft.com/tomcat-valves/

To accomplish this the following article was really helpful: http://robupcraft.com/tomcat-valves/

请注意,要实现(并成功构建),您需要tomcat-catalina依赖项.

Note that for the implementation (and successful build), you need tomcat-catalina dependency.

这篇关于tomcat8-400的自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆