如何在java服务器页面中显示阿拉伯语单词? [英] How to display Arabic word in java server page?
问题描述
我正在使用 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.
我的环境:
- Java 1.7
- Tomcat 7.0 服务器
- Eclipse Juno 版本
- Mysql
谁能帮我解决这个问题?
Can anyone help me resolving this problem?
推荐答案
您需要设置正确的字符编码 utf8 或 utf16一个>
You need to set the proper character encoding utf8 or utf16
在您的 JSP 中,您需要为编码插入页面指令
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("ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي");
}
请注意,如果您有包含阿拉伯字母的字符串文字,则该文件也必须保存在 utf8
或 utf16
Note that if you have String literals containing arabic letter then the file also has to be saved in utf8
or utf16
这篇关于如何在java服务器页面中显示阿拉伯语单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!