Tomcat 9中的编码问题“在RFC 7230和RFC 3986中定义了有效字符”

时间:2019-06-27 15:35:00

标签: java http encoding character-encoding tomcat9

我正在使用非常老旧的软件工作,该软件可与servlet配合使用,并且URL中包含重音符号和其他奇怪的字符。 几周前,该软件已从JDK7升级到JDK11,服务器已从Tomcat6升级到Tomcat9。

我尝试过:

- Using URLEncoder in the java part and encodeURI in the javascript part and it works fine, but there are hundreds of places that need this change and it's complicated because it's easy to make a mistake.
- Use the encodeURI in the server.xml of Tomcat but it doesn't change anything. And I've added the relaxedQueryChars tag, but it doesn't accept accents.
- The last thing that I've tried is to add a filter, to try to encode the params of the request, in the web.xml but it doesn't work when the error appears and there's no option to change the order. And another problem is that the ServletRequest has no setParameter so if I can solve the order filter problem I have this one...

我收到此错误:

Estado HTTP 400 – Bad Request 
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 

该代码在Tomcat6中运行完美,但是通过升级,我们解决了这个问题。 我正尝试获得一种服务器配置解决方案,以避免使用代码编码,但我不知道我还能尝试什么...

谢谢!

1 个答案:

答案 0 :(得分:0)

最后,我们决定安装Tomcat8而不是9,因为Tomcat8.5中引入了编码更改。

这是一种解决方法,它不能解决真正的编码问题。但是,实际上,尝试在代码的每个部分中使用encode函数都是冒险的,因为它可能会产生其他类型的问题。