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:
- Java 1.7
- Tomcat 7.0 server
- Eclipse Juno version
- Mysql
Can anyone help me resolving this problem?
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
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.
来源:https://stackoverflow.com/questions/26629624/how-to-display-arabic-word-in-java-server-page