Servlet在Mac上用美国国际键盘得到奇怪的字符 [英] Servlet gets weird character with US International keyboard on Mac

查看:160
本文介绍了Servlet在Mac上用美国国际键盘得到奇怪的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表单,我可以输入一些字符。这些字符被发送到执行getBytes并打印字节的servlet。 ã的正确UTF-8字节是-61和-93,但我得到-52和-93。 :(

I have a simple form where I can type some characters. These characters are sent to a servlet which does a getBytes and print the bytes. The correct UTF-8 bytes for a "ã" are -61 and -93, but I get -52 and -93. :(

我试过一切来理解和解决这个问题,但没有什么工作,我的机器上的一切都应该是UTF-8,所以我怀疑它与美国国际键盘我已经使用了20年。

I tried everything to understand and fix this, but nothing worked. Everything on my machine should be UTF-8 so I suspect it has to do with the US International keyboard I have been using for 20 years.

有聪明的灵魂有从-52和-93来自哪里的线索?

Does any smart soul have a clue from where -52 and -93 are coming from?

FIXED on Jetty:请参阅下面的答案。

FIXED on Jetty: See my answer below.

Tomcat上的BROKEN:如何让tomcat了解MacRoman(x-mac-roman) Mac键盘?

BROKEN on Tomcat: How to get tomcat to understand MacRoman (x-mac-roman) charset from my Mac keyboard?

推荐答案

这是 Mac OS罗马字符编码。(0xBB == -52。)

That is the Mac OS Roman character encoding. (0xBB == -52.)

有些事要检查:


  • getBytes(string,UTF-8) UTF-8)。

  • 表单应以UTF-8格式发送: response.setContentType(text / html ; charset =UTF-8); 。在JSP <%@ page pageEncoding =UTF-8%>

  • form action =...accept-charset =UTF-8>

  • getBytes(string, "UTF-8") and new String(bytes, "UTF-8").
  • The form should have been sent in UTF-8: response.setContentType("text/html; charset="UTF-8");. In a JSP <%@page pageEncoding="UTF-8"%>
  • <form action="..." accept-charset="UTF-8">

没有任何帮助:

As all that did not help:

href =http://wiki.apache.org/cocoon/RequestParameterEncoding>您的网络应用程序(web-xml)中的请求过滤。

Set the request filtering in your web application (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>

这篇关于Servlet在Mac上用美国国际键盘得到奇怪的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆