每当我尝试在Mozilla Firefox浏览器中将特殊字符放入URL中时,如下所示
要么
Tomcat返回HTTP状态400 - 错误请求和异常堆栈跟踪,如下所示。
Type Exception Report
Message Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Exception
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:474)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)
Note The full stack trace of the root cause is available in the server logs.
令人惊讶的是,具有特殊字符的相同网址可在Google Chrome浏览器中正
我有以下问题1)我应该在tomcat配置文件中做些什么更改,以便它不应该返回400状态代码和异常堆栈跟踪? 2)为什么Mozilla Firefox无法对URL进行编码?
注意:我已经在tomcat 9中部署的应用程序中为4XX类型的状态代码配置了一个公共页面,但问题是tomcat在第一个位置返回400个错误请求http状态代码。
从这里查看relaxedPathChars和relaxedQueryChars https://tomcat.apache.org/tomcat-8.5-doc/config/http.html你需要将它们设置为允许的所有先前字符而不转义