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-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).
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
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
Uploading a file to a server using JSP
Uploading an Image to a Database using JSP
A JSP page that gets properties from a bean
The taglib, tag, include, attribute and the variable Directive in JSP
Scriptlets and Expressions in JSP