Tomcat接收请求符号转义异常

来源:互联网 发布:logo设计软件下载 编辑:程序博客网 时间:2024/06/14 05:54

最近部署项目的时候,由于MIS配置的是Tomcat 8.5的服务端,导致Web应用不正常,报HTTP 400错误(Chrome无异常、IE报错)。问题原因初步判断为8.5版本的服务端接收请求不会对符号进行转义,Chrome不异常的原因或许是浏览器自身转义了。具体错误信息如下:

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

查阅了大量资料后,有两种解决方案:

Plan 1:
更换低版本的Tomcat来规避这种问题。

Plan 2:
在conf/catalina.properties中最后添加一行:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

重启服务器后,解决问题。

官方指南地址:http://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html

官方说明:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASHIf this is true ‘%2F’ and ‘%5C’ will be permitted as path.delimiters.If not specified, the default value of false will be used.