如何在Java服务器页面中显示阿拉伯语单词? [英] How to display Arabic word in java server page?

查看:117
本文介绍了如何在Java服务器页面中显示阿拉伯语单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 java 中的 Eclipse Kit 创建一个简单的Web应用程序.我需要在Java服务器页面中显示阿拉伯语单词.

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

在我的Web应用程序中,我能够将阿拉伯语言存储到我的数据库(MYSQL)中,然后使用jdbc模板(spring框架)从该数据库中检索,但是我无法在该网页中显示该阿拉伯词.表示Java服务器页面.

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.

我的环境:

  1. Java 1.7
  2. Tomcat 7.0服务器
  3. Eclipse Juno版本
  4. Mysql

有人可以帮我解决这个问题吗?

Can anyone help me resolving this problem?

推荐答案

您需要设置正确的字符编码 utf8或utf16

You need to set the proper character encoding utf8 or utf16

在您的JSP中,您需要插入page指令进行编码

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>

在Servlet中,您需要在响应对象中设置内容类型

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("ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي");
}

请注意,如果您的字符串文字包含阿拉伯字母,则文件也必须保存在utf8utf16

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

这篇关于如何在Java服务器页面中显示阿拉伯语单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆