Where to add the UTF-8 extension on an HTML page?

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

I do not know where I should add tags. Any rules are followed. Please let me know where to add the encoding. Do I need to add "ApplicationLoader.js" at the end or only after 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 easier for you to understand my situation in detail, and now I am no more than a guy new to training. As I understand it, I will explain my problems to you.

  • I created a webapplication project in Eclipse in which I created a class for connecting JDBC to MySQL.
  • I have a class in serveride that gets the user profile value from my webapp text field and saves it to the database.
  • I am using jQuery plugin to translate from English to Arabic.
  • I have an HTML page in which, as stated in the above part of the question, I have tags in which I added charset = "utf-8" to indicate unicode.
  • I use dwr to get values ​​in js and send them to the server.
  • I changed the input language on the computer to Arabic and my Mozilla firefox locale to Arabic.

I can enter the English values ​​in mysql and I can get it, but when I enter the Arabic value it will not be saved. JDBC Error

 java.sql.SQLException: Incorrect string value: '\xD8\xB3\xD9\x84\xD8\xA8...' 

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

+3
source share
3 answers

If the Content-Type header is present in the headers of the HTTP response, then this will override the metadata headers. Very often, this header is already provided by default by the web server, and most often the encoding is missing (which will assume the default encoding for the client, which is often ISO-8859-1). In other words, metadata headers are usually interpreted only when resources are opened locally (rather than HTTP). Most likely, this is the reason your meta headers did not seem to work when transmitted over HTTP.

You can use Firebug or Fiddler2 to define HTTP response headers. The following is the Firebug screen:

alt text

You can configure general settings for HTTP response headers at the web server level. You can also customize it based on a query at the programming language level. Since it is unclear which web server / programming language you are using, I cannot explain in detail how to configure it.


Update : according to the symptoms of the problem, which are the following typical MySQL exception:

 java.sql.SQLException: Incorrect string value: '\xD8\xB3\xD9\x84\xD8\xA8...' 

The byte sequence D8 B3 D9 84 D8 A8 is a valid UTF-8 sequence that represents those Ψ³Ω„Ψ¨ characters ( U + 0633 , U + 0644 and U + 0628 ). So the HTTP part is fine. You mentioned that you are using Jetty 6 as a servletcontainer. Later Jetty 6 builds already support UTF-8 out of the box.

However, the problem lies in the DB part. This exception indicates that the encoding that DB / table was instructed to use does not support this byte sequence. This can happen when DB / table has not been instructed to use UTF-8.

To fix part of the database, execute these 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 .

+10
source

It is usually enough to declare the encoding of the main document once, either through the content-type header (see @BalusC answer for a detailed explanation), or, if it is not available, a meta tag.

If you are using a meta tag, make sure it is on the first line of the head section.

No need to explicitly specify a character set for script files.

Of course, all the content you work with must be encoded in UTF-8 for this to work. This is not enough to simply knock a meta tag for a content such as content. (But you probably know about that.)

+3
source

Thus:

 <script type="text/javascript" src="[path]/myscript.js" charset="utf-8"></script> 
+2
source

All Articles