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

By: Markus Kuhn Emailed: 1700 times Printed: 2205 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

Comments(1)


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: `java.net.BindException: 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 )
What are the different scopes in JSP?
JSP CheckBox Example
The JSP Program running first Time.
Tags using in jsp
Retrieving a Portion of a String
Comparison operators in JSP
Automatically Including Preludes and Codas in JSP
The BodyTag Interface in JSP
JSP Example to connect to MS SQL database and retrieve records
Using UTF-8 in JSP / ASP / HTML pages.
Writing your first JSP page
Getting Started with JSP
The Exception Object in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
What is JSP?
Most Emailed Articles (in JSP)
What is JSP?
Declaring variable in JSP
A Servlet That Generates HTML
Retrieving a Portion of a String
JSP Example to connect to MS SQL database using Tomcat Connection Pool
The Application Object in JSP
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Scriptlets
Server Side Programming
Syntax For JSP Declaratives
Embedding java codes in jsp sciptlets
Tags using in jsp
JSP pages in servlet