问题
In Tomcat (v8.5.24) an URL with a query parameter containing an unencode curly brace ("{") produces a 400 error.
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>
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)
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.
So no luck rendering a custom 400 page in this scenario? Or is there any workaround?
回答1:
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.
To accomplish this the following article was really helpful: http://robupcraft.com/tomcat-valves/
Note that for the implementation (and successful build), you need tomcat-catalina dependency.
来源:https://stackoverflow.com/questions/50736363/tomcat8-custom-error-page-for-400