£符号显示为一个菱形,中间有一个问号 [英] The £ sign is shown as a diamond with a question mark in the middle

查看:7306
本文介绍了£符号显示为一个菱形,中间有一个问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个webapp,涉及向用户显示财务数据。来自英国,并使用GBP£作为货币,这个字符被使用了很多。

I'm creating a webapp which involves displaying financial data to the user. Being from the UK and using GBP £ for currency, this character is used a lot.

然而,现在,每个时候,£显示为一个钻石与一个问题标记在中间,并在网页上它抛出一个无效的字符UTF-8字节1的1字节字符串。

However, every now and then, the £ is shown as a diamond with a question mark in the middle, and on the web page it throws an invalid charachter UTF-8 byte 1 of 1 byte string.

有一个UTF安全的方式来显示£ sign?这里是我现在在做什么的例子:

Is there a UTF safe way to display the £ sign? Here is an example of what I am doing at the moment:

 "Rent Per Annum: £" + '${tenant.currentRent}'


推荐答案

以下一个或多个原因:


  1. JSP文件不是由编辑器(Eclipse,Netbeans,记事本等)

  1. The JSP file is not by the editor (Eclipse, Netbeans, Notepad, etc) been saved using UTF-8 encoding.

服务器在通过网络发送之前未使用UTF-8将JSP生成的字符解码为字节流

The server didn't use UTF-8 to decode the characters produced by the JSP to a byte stream before sending it over network.

浏览器未使用UTF-8编码从网络到字符的字节流。

The browser didn't use UTF-8 to encode the byte stream from the network to characters.

这些问题可以如下解决:

Those problems can be solved as follows:


  1. 编辑器使用UTF-8保存JSP文件。我不熟悉STS,但我知道它是基于Eclipse的,所以它可能会与标准Eclipse相同。转到窗口>首选项>常规>工作区>文本文件编码,然后在下拉菜单中选择正确的编码。

  1. Configure the editor to save JSP files using UTF-8. I'm not familiar with STS, but I know that it is Eclipse based, so it'll probably be the same as in standard Eclipse. Go to Window > Preferences > General > Workspace > Text File Encoding and then pick the right encoding in the dropdown.

另一种方法是使用HTML实体& pound; (由另一个应答者建议),这样,在保存JSP文件的编码时不再相关。字符串& pound; 中涉及的所有字符已经由基本ASCII编码支持(世界上使用的每个正确的字符编码基本上扩展ASCII,

An alternative is to use the HTML entity £ (as suggested by the other answerer), this way it's not relevant anymore in which encoding the JSP file is saved. All characters involved in the string £ are supported by the basic ASCII encoding already (every decent character encoding used in the world basically "extends" ASCII, so it'll always work) and the HTML interpreter (the webbrower) will translate the HTML entity into the right character.

服务器必须被指示使用UTF-8(通常工作),HTML解释器(网络浏览器)会将HTML实体翻译成正确的字符。以解码JSP输出。这可以在每个JSP基础上由

The server has to be instructed to use UTF-8 to decode the JSP output. This can on a per-JSP basis be done by

<%@page pageEncoding="UTF-8" %>

或在应用程式范围内通过

or on an application-wide basis by

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>


  • 必须指示浏览器使用UTF-8编码HTTP响应。这可以通过将HTTP响应 Content-Type 头的 charset 属性设置为UTF-8来解决,

  • The browser has to be instructed to use UTF-8 to encode the HTTP response. This is to be solved by setting the charset attribute of the HTTP response Content-Type header to UTF-8, which is already implicitly done by the solution to cause #2.



    另请参阅:




    • Unicode - 如何获取字符?

    • See also:

      • Unicode - How to get the characters right?
      • 这篇关于£符号显示为一个菱形,中间有一个问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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