Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Arabic language support in JAVA  RSS feed

 
murugesan govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have developed the Email portlet and datas are returned from webservices. In my .java file, I have the variable messageo[1] which returns the email title and title may be in English or Arabic.

When variable has English message then it works fine for me but when variable has Arabic message it displays title like "???".

If I test the Webservices(.wsdl file) then it's displays Arabic message, I think problem with my .java file because it's not reading Arabic message in .java file.

I tested the code like below but it's not working in both case.
In java:
String value = new String(messageo[1].getBytes("ISO-8859-1"), "UTF-8");
and
String value = new String(messageo[1].getBytes(), "UTF-8");

In JSP:
<%@ page language="java"contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

Pls advise me,

Regards
Murugesan
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String value = new String(messageo[1].getBytes("ISO-8859-1"), "UTF-8");

This can't work, because ISO-8859-1 does not contain Arabic characters. So you can't use it to encode the text. Also, decoding an array of ISO-8859-encoded characters with UTF-8 doesn't work.

String value = new String(messageo[1].getBytes(), "UTF-8");

This doesn't work either, because it encodes the string using the platform default encoding - which may not support Arabic. But "messageo" is a Java String already - so encoding it to something else, and then decoding it back to Unicode accomplishes nothing.

The first thing to do is to ascertain which encoding is used for sending the characters in the web service. The documentation of whichever service you're using should specify that. It may well be Unicode (in which you don't need to do anything, because Java uses Unicode internally, too).

That the console shows question marks doesn't mean much - most consoles/terminals don't support output of non-ASCII characters.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try using "Windows-1256" for both the pageEncoding and the charset in your JSP.

Let me know what you get.

Regards,
 
murugesan govind
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I added the code like below but it's not working,

In JSP:
<%@ page language="java" contentType="text/html; charset=Windows-1256" pageEncoding="Windows-1256"%>

Pls advise me,

Regards
Murugesan
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try like this ...

It's working fine with me ...

Regards,
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!