Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tamil characters appear as question marks when using JSTL fmt library and properties files

I am using JSTL fmt taglib to show Tamil characters. But I could not show any Tamil characters. Instead of showing Tamil characters, it's showing question mark characters as in ??????. I tried for Hindi and it shows question marks as well. What should I do now?

Here is my code. I simply try to print Hello World in Tamil.

fileproperty.properties:

helloworld=வணக்கம் உலகம்

Hello.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org  /TR/html4/loose.dtd">
<html>
  <fmt:setLocale value="ta-IN"/>
  <fmt:setBundle basename="fileproperty"/>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Home</title>
  </head>
  <body>
    <fmt:message key="helloworld"/>
  </body>
</html> 
like image 887
user1942241 Avatar asked Jan 02 '13 07:01

user1942241


1 Answers

Properties files do not support UTF-8. Read the javadoc:

... the input/output stream is encoded in ISO 8859-1 character encoding ...

(as you seem to be using Eclipse, I wonder if you have ever actually carefully read the warning message which it would show while saving such a .properties file for the first time)

Basically, you need the native2ascii tool to convert UTF-8 saved properties files to proper ISO-8859-1 properties file format. Rename your UTF-8 properties file to include utf8 somewhere in the filename and convert it as follows:

native2ascii –encoding UTF-8 fileproperty.utf8.properties fileproperty.properties

Hereby any character which is not covered by the ISO-8859-1 charset will be replaced by an unicode codepoint sequence like \u1234.

However, Eclipse has already builtin support for it. You should make use of it. You should be opening properties files in a "Properties file editor" instead of a "Text editor" (it's recognizable by the property values being highlighted in blue instead of unhighlighted in black). If it doesn't do that by default already, rightclick the properties file and choose Open With > Properties File Editor. If you paste வணக்கம் உலகம், then Eclipse will (should) automatically convert it to \u0BB5\u0BA3\u0B95\u0BCD\u0B95\u0BAE\u0BCD \u0B89\u0BB2\u0B95\u0BAE\u0BCD\u008D.

Save it once again, clean/rebuild/redeploy/restart and try once again. It should now work fine.

See also:

  • Unicode - How to get the characters right?

Unrelated to the concrete problem, your @page is full of values which are already the default. Just the following is sufficient.

<%@page pageEncoding="UTF-8"%>
like image 187
BalusC Avatar answered Sep 19 '22 17:09

BalusC