本文介绍了在 HTML 页面中在哪里添加 UTF-8 扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在脚本标签的末尾添加 charset="utf-8" 以完成到另一种语言的翻译.

我不知道我应该在哪里添加标签.遵守任何规则.请让我知道在哪里添加字符集.我需要在ApplicationLoader.js"的末尾添加还是只在jquery插件之后添加.请提出任何建议.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>我的网络应用</title><link href="css/jquery/jquery.ui.all.css" rel="stylesheet" type="text/css"/><script type="text/javascript" src="js/jquery-1.4.2.min.js" charset="utf-8"></script><script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js" charset="utf-8"></script><script type="text/javascript" src="js/jquery.depends.js" charset="utf-8"></script><script type="text/javascript" src="myemployeelist.js" ></script>

更新:

我会让你更容易地详细了解我的情况,而不是一个更多的家伙现在正在接受培训的新手.据我所知,我会向你解释我的问题.

  1. 我在 Eclipse 中创建了一个 webapplication 项目,我在其中创建了一个类用于到 MySQL 的 JDBC 连接.
  2. 我在服务器端有一个类,它从我的 web 应用程序中获取用户配置文件值文本框并保存在数据库中.
  3. 我正在使用 jQuery 插件进行从英语到阿拉伯语的翻译.
  4. 我有一个 HTML 页面,其中如问题的上述部分所述,我有我在其中添加了 charset="utf-8" 以指定 unicode 的标签.
  5. 我正在使用 dwr 获取 js 中的值并将其发送到服务器端.
  6. 我将计算机输入语言更改为阿拉伯语,并将我的 Mozilla firefox 语言环境更改为阿拉伯语.

我可以在 mysql 中输入英文值并且我可以检索它但是当我输入一个阿拉伯值,它不会被保存.JDBC 错误是

java.sql.SQLException: 字符串值不正确:'xD8xB3xD9x84xD8xA8...'

我不知道如何将我的服务器 Jetty 6 LANG 变量配置为 utf-8.请提出任何建议.谢谢.

解决方案

如果 , U+0644U+0628).所以 HTTP 部分没问题.您提到您使用 Jetty 6 作为 servletcontainer.Jetty 6 的后续版本已经开箱即用地支持 UTF-8.

然而,问题出在数据库部分.此异常表示指示 DB/表使用的字符集不支持此字节序列.当未指示 DB/表使用 UTF-8 时,可能会发生这种情况.

要修复数据库部分,请发出这些 MySQL 命令:

ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;ALTER TABLE table_name 转换为字符集 utf8 COLLATE utf8_general_ci;

对于未来的数据库/表,在 CREATE 语句中也使用 CHARACTER SET utf8 COLLATE utf8_general_ci.

I need to add the charset="utf-8" at the end of the script tags to get the translation to another language done.

I don know where all I should add the tags. Any rules are followed. Please let me know where to add the charset. Do i need to add at the end of "ApplicationLoader.js" or only after the jquery plugins. Any suggestion please.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Web App</title>

<link href="css/jquery/jquery.ui.all.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="js/jquery-1.4.2.min.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.depends.js" charset="utf-8"></script>
<script type="text/javascript" src="myemployeelist.js" ></script>


Update:

I will make it more easy for you to understand my situation in details and am not a more stuff guy am a newbie under training now.As far as I understood I will explain my problems to you.

  1. I created a webapplication project in Eclipse, in which I created a classfor JDBC connection to MySQL.
  2. I have a class in serverside which gets the users profile value from my webapptextbox and saves in DB.
  3. I am using jQuery plugin for doing translation from English to Arabic.
  4. I have an HTML page in which as stated in the above part of question I have thetags in which I added the charset="utf-8" to specify unicode.
  5. I am using dwr to get the values in js and send it to server side.
  6. I changed my computer input language to Arabic and my Mozilla firefox locale toArabic.

I am able to enter the English values in mysql and I am able to retrieve it but when I enter a Arabic value it's not getting saved. The JDBC error is

java.sql.SQLException: Incorrect string value: 'xD8xB3xD9x84xD8xA8...'

I dont know how to configure my server Jetty 6 LANG variable to utf-8. Any suggestion please. Thanks.

解决方案

If a Content-Type header is present in the HTTP response headers, then this will override the meta headers. Very often, this header is already by default supplied by the webserver and more than often the charset is absent (which would assume client's default charset which is often ISO-8859-1). In other words, the meta headers are generally only interpreted whenever the resources are opened locally (not by HTTP). Big chance that this is the reason that your meta headers apparently didn't work when served over HTTP.

You can use Firebug or Fiddler2 to determine the HTTP response headers. Below is a Firebug screen:

You can configure the general setting for HTTP response headers at webserver level. You can also configure it on a request basis at programming language level. Since it's unclear what webserver / programming language you're using, I can't go in detail about how to configure it accordingly.


Update: as per the problem symptoms, which is the following typical MySQL exception:

The byte sequence D8 B3 D9 84 D8 A8 is a valid UTF-8 sequence which represents those characters سلب (U+0633, U+0644 and U+0628). So the HTTP part is fine. You mentioned that you were using Jetty 6 as servletcontainer. The later builds of Jetty 6 already support UTF-8 out of the box.

However, the problem is in the DB part. This exception indicates that the charset the DB/table is been instructed to use doesn't support this byte sequence. This can happen when the DB/table isn't been instructed to use UTF-8.

To fix the DB part, issue those MySQL commands:

ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

And for future DB/tables, use CHARACTER SET utf8 COLLATE utf8_general_ci in CREATE statement as well.

这篇关于在 HTML 页面中在哪里添加 UTF-8 扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:40