赞
踩
近期在做一个关于CMS建站平台的项目在后台上传图片的时候遇到了 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986这个错误,翻了许多博客发现用的方法都不行(基本上都是在Tomcat根目录的config中修改server.xml文件)于是集思广益花了我一个星期的时间终于解决了。
首先在我们Tomcat的根目录中找到我们的catalina.properties文件(文件位置:Tomcat根目录\conf\catalina.properties)。找到注释掉的一行 #tomcat.util.http.parser.HttpParser.requestTargetAllow=| ,改成tomcat.util.http.parser.HttpParser.requestTargetAllow=|{},表示把{}放行。
# This system property is deprecated. Use the relaxedPathChars relaxedQueryChars
# attributes of the Connector instead. These attributes permit a wider range of
# characters to be configured as valid.
# Allow for changes to HTTP request validation
# WARNING: Using this option may expose the server to CVE-2016-6816
#tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
之后则是跟众多博主的方法一样修改server.xml文件(文件位置:Tomcat根目录\conf\server.xml),但是修改的内容跟众多博主的不一样。在service.xml中添加realxedQueryChars属性,属性的值为"[,],|,{,},^,\,`,",<,>"。
<!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL/TLS HTTP/1.1 Connector on port 8080 --> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8" relaxedQueryChars="[,],|,{,},^,\,`,",<,>"/> <!-- A "Connector" using the shared thread pool--> <!-- <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> -->
修改这两处之后重新启动Tomcat服务器再运行项目,图片就能够成功上传,不会再在控制台上遇到java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986错误的提示了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。