Skip to main content

Java Web application and UTF-8

Java and UTF-8
Generally we can rely on Java as long as source strings are properly encoded. Please refer link:
  1. http://java.sun.com/docs/books/tutorial/i18n/text/convertintro.html,
  2. http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp
Tomcat and UTF-8
  1. JSP pages must include the header: <%@ page contentType="text/html; charset=UTF-8"%>
  2. Update the file $CATALINA_HOME/conf/server.xml : add attribute URIEncoding="UTF-8" in Connector tag
  3. Add filter as suggested in the link : http://wiki.apache.org/tomcat/Tomcat/UTF-8
  4. Tomcat UTF-8 Problem with request.getParameter(), http://answers.google.com/answers/threadview?id=580467
  5. useBodyEncodingForURI : http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html
MySql and UTF-8
  1. We need our databases and tables to be in utf8 character set : ALTER tables with an SQL statement like - ALTER DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci;
  2. Start mysql-demon using option "--character-set-server=utf8" : mysqld ócharacter-set-server=utf8
  3. May be useful : http://lists.mysql.com/java/8081
JDBC and UTF-8
  1. We can also use useUnicode and characterEncoding properties to configure the JDBC driver to use UTF-8.
  2. http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-charsets.html
  3. As suggested in the link we can use utf8 encoding either by configuring utf8 as the default server character set in MySql?, or by configuring the JDBC driver to use UTF-8 through the characterEncoding property
XML and UTF-8
  1. Add encoding="UTF-8" in (JR)XML header.
Others
  1. http://blogs.warwick.ac.uk/kieranshaw/entry/utf-8_internationalisation_with
  2. UTF-8 in JBoss/Tomcat + MySQL + Hibernate + JavaMail

Comments

Popular posts from this blog

Java and “\u” ( blackslash u )

This article is related to escaping of “\u” backslash u [Unicode character] in Java Problem Statement: I have a string which consists of a DOS path something like "\sample\user_data\example".The “\u” (backslash u) in “\user_data” above gives “an invalid Unicode” JavaScript error in IE and hence my page isn’t displayed. I tried to replace “\u” (backslash u) in the string with something like "\ u"(backslash u) as I was not able to escape it. This also does not work . Java complier does not allow “\u” (backslash u) character and gives "Invalid unicode character sequence" error when I use it with replaceAll. Que 1: Can I escape the \u character some how in Java or JavaScript? Que 2: How can I replace all "\u" character in a string with something else like "\ u"? I have posted this query to some of the Java and JavaScript related groups. Here are the solutions I found Before going into the details about solution let us

MySQL :: tinyInt1isBit

One can enter values apart from 0 and 1 (say 2,3,?100) in a field with tinyint(1) type in MySql. MySql doesn?t complain. Now if you want to read inserted data using PHP it will return value as it is, however this will not work with Java. Java will throw an exception while reading same MySql data. Java treats tinyint(1) as Boolean and returns only true or false. Two solution either we can make our column tinyint(something > 1), or can add the connection property 'tinyInt1isBit=false' to our JDBC URL. Adding connection property 'tinyInt1isBit=false' to JDBC URL is risky since it will affect entire database data while reading the same using Java. Refer : http://forums.mysql.com/read.php?39,10652,10669#msg-10669

Every thing about ConcurrentHashMap

Why ConcurrentHashMap is better than Hashtable and just as good as a HashMap http://www.codercorp.com/blog/java/why-concurrenthashmap-is-better-than-hashtable-and-just-as-good-hashmap.html Why ConcurrentHashMap does not support null values http://anshuiitk.blogspot.com/2010/12/why-concurrenthashmap-does-not-support.html