Using UTF-8 in JSP / ASP / HTML pages.
By: Markus Kuhn
There are two ways in which a HTTP server can indicate to a client that a document is encoded in UTF-8:
- Make sure that the HTTP header of a document contains the line
Content-Type: text/html; charset=utf-8
if the file is HTML, or the lineContent-Type: text/plain; charset=utf-8
if the file is plain text. How this can be achieved depends on your web server. If you use Apache and you have a subdirecory in which all *.html or *.txt files are encoded in UTF-8, then create there a file .htaccess and add to it the two linesAddType text/html;charset=UTF-8 html AddType text/plain;charset=UTF-8 txt
A webmaster can modify /etc/httpd/mime.types to make the same change for all subdirectories simultaneously. - If you cannot influence the HTTP headers that the web server prefixes to
your documents automatically, then add in a HTML document under HEAD the
element
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
which usually has the same effect. This obviously works only for HTML files, not for plain text. It also announces the encoding of the file to the parser only after the parser has already started to read the file, so it is clearly the less elegant approach.
The currently most widely used browsers support UTF-8 well enough to generally recommend UTF-8 for use on web pages. The old Netscape 4 browser used an annoyingly large single font for displaying any UTF-8 document. Best upgrade to Mozilla, Netscape 6 or some other recent browser (Netscape 4 is generally very buggy and not maintained any more).
Archived Comments
1. This all works fine, but when I read records from my MySQL datatable and want to Response.Write them
View Tutorial By: Ayac at 2011-10-31 10:58:21
Comment on this tutorial