By: Markus Kuhn Viewed: 1379 times Printer Friendly Format
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-8if the file is HTML, or the line
Content-Type: text/plain; charset=utf-8if 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 lines
AddType text/html;charset=UTF-8 html AddType text/plain;charset=UTF-8 txtA 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
<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).
Most Viewed Articles (in JSP )
Latest Articles (in JSP)
Comment on this tutorial
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews