未显示ISO-8859-1字符

时间:2011-09-05 19:49:10

标签: mysql jsp character-encoding iso-8859-1

我的JSP页面没有显示拉丁字符。 América变成Am?rica。 我已经把每个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

2 个答案:

答案 0 :(得分:2)

  

... América变成Am?rica ......

     

... 虽然我的数据库表显示拉丁字符很好 ...

字符在数据库表中显示正常,并且您得到?,表示您的数据库表实际以不同的编码存储它,大多数可能是UTF-8(现在是获得world domination的推荐编码)。

所有内容更改为UTF-8,此问题应该消失。本文针对Java EE Web开发人员应该提供一个很好的介绍:Unicode - How to get the characters right?

答案 1 :(得分:0)

BalusC 可能有正确的答案。但是,请注意,现代浏览器将ISO-8859-1误解为Windows代码页1252(出于历史原因),并且这两种编码之间存在小的差异。因此,如果您的数据真的在ISO-8859-1中编码,那么您运气不好 - 您无法提供此编码,您需要重新编码所有数据(然后你应该转到UTF-8)。