in this post I will address the Arabic encoding problems.
any one may face one or more of the following scenarios:
- Retrieving Arabic data from database and wanna display it in a web page correctly.
- Getting encoded Arabic data from web page and reading it correctly.
for the first Scenario Retrieving Arabic data from database and wanna display it in a web page correctly.
it may works great with you by just adding the following page Encoding to your jsp page
<%@ page pageEncoding="windows-1256" %>
and if it didn't work you may need to do encode the retrieved Arabic String as follows:
String value2 = new String(arabicString.getBytes(), "Cp1256");
and this will encode the Arabic letters as &#XXX;:
for example "المستخدم" word will be translated to "المستخدم" inside the HTML page.
for the second Scenario Getting encoded Arabic data from web page and reading it correctly.
you will need to manipulate the retrieved Arabic encoded serious "المستخدم" as follows:
/** * decode the passed value * @return the encoded arabic value * @param value */ private String denodeToArabic(String value) { if(value.indexOf("&#")==-1) return value; String newString =""; value = value.replaceAll("&#",""); String[] characters = value.split(";"); for(int i=0; i<characters.length; i++){ if(characters[i].startsWith(" ")) newString +=" "; else if(characters[i].trim().length()!=4) newString += characters[i].trim(); else newString +=(char)Integer.valueOf(characters[i].trim()).intValue()+""; } return newString; }
References:
-
http://download.oracle.com/docs/cd/B10500_01/server.920/a96529/appa.htm#958278 - http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html

Recent comments
2 weeks 17 hours ago
15 weeks 5 days ago
16 weeks 12 hours ago
16 weeks 12 hours ago
27 weeks 3 days ago
31 weeks 4 days ago
32 weeks 5 days ago
1 year 2 days ago
1 year 2 days ago
1 year 4 weeks ago