1

I am creating a simple web application using Eclipse Kit in java. I need to display the Arabic word into a java server page.

In my web application, I am able to store the Arabic language into my database (MYSQL) and then retrieve from that database using a jdbc template (spring framework), but i could not display the Arabic word into my webpage, which means java server page.

My Environment:

  1. Java 1.7
  2. Tomcat 7.0 server
  3. Eclipse Juno version
  4. Mysql

Can anyone help me resolving this problem?

Mikel Urkia
  • 2,087
  • 1
  • 23
  • 40
FELIX RAJ
  • 13
  • 1
  • 4

2 Answers2

1

you need to set http response encoding style UTF8

like...

<%@ page pageEncoding="UTF-8" %>

Also see this article for more Reference here

try this code may help you.

user2428568
  • 223
  • 1
  • 4
  • 18
0

You need to set the proper character encoding utf8 or utf16

In your JSP you need to insert the page directive for the encoding

<%@ page pageEncoding="utf-8" %>
<!DOCTYPE html>
<html>
<body>
    <h2>ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي</h2>
</body>
</html>

In a Servlet you need to set the content type in the response object

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException {
    resp.setContentType("text/plain; charset=utf-8");
    PrintWriter writer = resp.getWriter();
    writer.write("ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي");
}

Note that if you have String literals containing arabic letter then the file also has to be saved in utf8 or utf16

Community
  • 1
  • 1
A4L
  • 17,353
  • 6
  • 49
  • 70