不显示 ISO-8859-1 字符
我的 JSP 页面不显示拉丁字符。美国变成了美国。 我已经将其放在每个 JSP 的顶部:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>`
并放在 web.xml 的顶部:
<?xml version="1.0" encoding="ISO-8859-1"?>
还尝试设置与数据库的连接:
jdbc:mysql://localhost:3306/database3?charSet=ISO8859-1
并且我还在项目的属性上将其配置为 ISO-8859-1,但没有成功,尽管我的数据库表显示拉丁字符很好。
我缺少什么?
我的数据库的状态是:
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe Ver 14.14 Distrib 5.5.15, for Win32 (x86)
Connection id: 6
Current database: database3
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.5.15 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 12 min 22 sec
Threads: 2 Questions: 102 Slow queries: 0 Opens: 50 Flush tables: 1 Open tables: 27 Queries per second avg: 0.137
我的表的状态是:
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| address | InnoDB | 10 | Compact | 4 | 4096 | 16384 | 0 | 16384 | 4194304 | 5 | 2011-09-07 18:46:49 | NULL | NULL | utf8_general_ci | NULL | | |
如您所见,排序规则为 utf8_general_ci
。
MY JSP pages are not showing latin characters. América turns into Am?rica.
I've already put on top of every JSP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>`
and on top of the web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
Also tried to set on the connection with the database:
jdbc:mysql://localhost:3306/database3?charSet=ISO8859-1
And I also configured it to ISO-8859-1 on the project's properties with no success, although my database tables are showing the Latin characters just fine.
What am I missing?
The status on my database is:
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe Ver 14.14 Distrib 5.5.15, for Win32 (x86)
Connection id: 6
Current database: database3
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.5.15 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 12 min 22 sec
Threads: 2 Questions: 102 Slow queries: 0 Opens: 50 Flush tables: 1 Open tables: 27 Queries per second avg: 0.137
The status on my table is:
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| address | InnoDB | 10 | Compact | 4 | 4096 | 16384 | 0 | 16384 | 4194304 | 5 | 2011-09-07 18:46:49 | NULL | NULL | utf8_general_ci | NULL | | |
As you can see, collation is utf8_general_ci
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些字符在您的数据库表,并且您得到一个
?
作为结果,表明您的数据库表实际上以不同的编码存储它,很可能是 UTF-8(即现在推荐的编码以获得世界统治)。将所有内容更改为UTF-8,这个问题就会消失。这篇针对 Java EE Web 开发人员的文章应该给出一个很好的介绍:Unicode - 如何获得正确的字符?
That the characters display just fine in your database table and that you're getting an
?
as result, indicates that your database table is actually storing it in a different encoding, most likely UTF-8 (which is nowadays the recommended encoding to gain world domination).Change everything to be UTF-8 and this problem should disappear. This article which is targeted on Java EE web developers should give a good introduction: Unicode - How to get the characters right?
BalusC 可能有正确的答案。但是,还要注意,现代浏览器将 ISO-8859-1 错误地解释为 Windows 代码页 1252(由于历史原因),并且这两种编码之间存在细微差异。因此,如果您的数据确实采用 ISO-8859-1 编码,那么您就不走运了 – 您无法提供此编码,您需要重新编码所有内容你的数据(然后你应该转向UTF-8)。
BalusC probably has the right answer. However, also be aware that modern browsers mis-interpret ISO-8859-1 as Windows codepage 1252 (for historic reasons) and there are small discrepancies between those two encodings. So if your data really is encoded in ISO-8859-1 then you’re out of luck – you cannot serve this encoding, you need to re-encode all your data (and then you should move to UTF-8).