我有一个简单的表单,可以在其中输入一些字符。这些字符被发送到执行 getBytes 并打印字节的 servlet。 “ã”的正确 UTF-8 字节是 -61 和 -93,但我得到 -52 和 -93。 :(
我尝试了一切来理解和解决这个问题,但没有任何效果。我机器上的所有内容都应该是 UTF-8,所以我怀疑这与我已经使用了 20 年的美国国际键盘有关。
有聪明的人知道 -52 和 -93 是从哪里来的吗?
已在 Jetty 上修复:请参阅下面我的回答。
Tomcat 上损坏:如何让 tomcat 从我的 Mac 键盘理解 MacRoman (x-mac-roman) 字符集? https://stackoverflow.com/questions/10369014/how-to-get-tomcat-to-understand-macroman-x-mac-roman-charset-from-my-mac-keybo
那就是Mac OS 罗马字符编码 http://en.wikipedia.org/wiki/Mac_OS_Roman。 (0xBB == -52。)
需要检查的一些事项:
-
getBytes(string, "UTF-8")
and new String(bytes, "UTF-8")
.
- 该表单应以 UTF-8 格式发送:
response.setContentType("text/html; charset="UTF-8");
。在 JSP 中<%@page pageEncoding="UTF-8"%>
<form action="..." accept-charset="UTF-8">
因为这一切都没有帮助:
Set the 请求过滤 http://wiki.apache.org/cocoon/RequestParameterEncoding在您的 Web 应用程序 (web-xml) 中。
pom.xml 中的编码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>...</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>...</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)