Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 class for JDBC connection to MySQL.
  2. I have a class in serverside which gets the users profile value from my webapp textbox 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 the tags 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 to Arabic.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
88 views
Welcome To Ask or Share your Answers For Others

1 Answer

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:

alt text

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:

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...