简体   繁体   English

特殊字符变形为它们的XML数字参考Java tomcat9

[英]Special Characters getting morphed to their XML number reference Java, tomcat9

I recently updated one of my apps from Tomcat6 to Tomcat9 and Java8 to OpenJDK 11, Linux and I was seeing a problem with my forms when I submit special characters such as Japanese/Chinese characters. 我最近将自己的一个应用程序从Tomcat6更新为Tomcat9,将Java8更新为OpenJDK 11,Linux,并且在提交特殊字符(例如日文/中文字符)时,表单出现问题。

It doesn't look like the issue is coming from code since I tried running the app in my old Tomcat6/Java8 box and the special characters are not being converted. 由于我尝试在旧的Tomcat6 / Java8框中运行该应用程序,并且特殊字符未转换,因此该问题似乎不是源于代码。 It might be some server configuration but I'm not really sure where to look. 可能是一些服务器配置,但是我不确定在哪里看。

I input "法敲中" and it gets converted into &# 27861; 我输入“法敲中”,它将转换为法 &# 25970; 敲 &# 20013; 中 once I submit my forms 一旦我提交表格

This seems to be normal behavior. 这似乎是正常现象。 The numbers you see are XML encoding that is equivalent to "\法\敲\中" - unicode codes for the symbols "法敲中" XML parser wants to ensure that the xml String could be passed with simple English encoding (ISO8859-1) and those symbols could not be passed in that encoding. 您看到的数字是等效于“ \\ u6cd5 \\ u6572 \\ u4e2d”的XML编码-符号“法敲中”的Unicode代码XML解析器希望确保xml字符串可以通过简单的英语编码传递(ISO8859-1 ),则这些符号无法在该编码中传递。 So it converts it to unicode equivalents so later it could still "understand" and decode non-standard symbols even though ISO8859-1 charset doesn't support them. 因此,它将其转换为等效的unicode,因此即使ISO8859-1字符集不支持非标准符号,它仍可以“理解”并解码非标准符号。 This is a precaution since if you work with UTF-8 it would pass just fine. 这是一种预防措施,因为如果您使用UTF-8,它将通过就可以了。 Anyway I used a tool to test it that I find very useful. 无论如何,我使用一种工具来测试它,我发现它非常有用。 It converts any String into Unicode characters and back. 它将任何String转换为Unicode字符并返回。 Here is what I did: 这是我所做的:

System.out.println(StringUnicodeEncoderDecoder.encodeStringToUnicodeSequence("法敲中"));

And the result came as \法\敲\中 . 结果为\法\敲\中 If you wish to use this tool, it is part of the MgntUtils open source library (written by me). 如果您想使用此工具,它是MgntUtils开源库(由我编写)的一部分。 Here are the links to Maven Artifacts , Github (including sources and javadoc) and javadoc . 这是Maven ArtifactsGithub (包括源代码和javadoc)和javadoc的链接 Also you can read about the library here 您也可以在这里阅读有关图书馆的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM