Using UTF-8 in JSP / ASP / HTML pages.

By: Markus Kuhn Emailed: 1643 times Printed: 2110 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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 line
      Content-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 lines
      AddType 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).

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

This all works fine, but when I read records from my MySQL datatable and want to Response.Write them on the page, my special characters become corrupted even though I have my tables in utf8 as a default and I send a "SET NAMES 'utf8'" before I query the database... where is the problem? I use the 3.1 ODBC for MySQL... could that be it? Let's try the 5.1...

View Tutorial          By: Ayac at 2011-10-31 10:58:21

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Markus Kuhn
Using UTF-8 in JSP / ASP / HTML pages.
What is UTF-8?
Unicode vs ISO 10646?
What is Unicode?
What is UCS? What is ISO 10646?

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Alert Example
JSP Program for display Date
Arithmetic Evaluation Using the Expression Language in JSP
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
IIS and Tomcat - how to configure to work together
The Session Object in JSP
JSP CheckBox Example
Combining Scriptlets with HTML
JSP Tags for SQL to connect to a database
Encrypting Passwords in Tomcat using Servlets
JSP Example to connect to MS SQL database using Tomcat Connection Pool
Sending Email using JSP
Using UTF-8 in JSP / ASP / HTML pages.
Using a DataSource from WebLogic in a JSP
Most Emailed Articles (in JSP)
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
Tags using in jsp
Tag libraries
What is JSP?
Click to Activate and Use this control
Closing Windows
Frame Object
Introduction to JSP expression language
Disabling Scriptlets in JSP using web.xml
Getting HTTP Request Headers in a JSP
What is JSP?
Cookies using JSP or Java Bean
Syntax For JSP Declaratives
JSP Program for display Date
Sessions in JSP