设置Java环境(Apache Tomcat)以编码UTF-8 [英] Setting Java Environment (Apache Tomcat) to encode UTF-8
问题描述
我想知道如何设置Java环境以UTF-8编码。
基本上我的JSP页面显示有一些阿拉伯语文本,但它们似乎没有正确编码。
当我在IDE中运行页面时,它工作正常,但在它们是主机的服务器上,它只是将其显示为问号。我只是想知道如何设置java环境或apache tomcat来编码UTF-8。
如有任何帮助,我们将不胜感激。
I want to know how to set-up the Java Environment to encode in UTF-8.
Basically I have JSP pages displayed with some Arabic text but they don't seem to be encoding right.
When I run the pages in the IDE it works fine but on the server where they are host it simple displays it as question marks. I just want to know how to set the java environment or apache tomcat to encode the UTF-8.
Any help will be appreciated.
推荐答案
您有一些具有不同影响级别的常规设置:
You have a few general settings with different impact levels:
(1)配置 JSP
页面以在utf-8中显示内容(位于jsp页面的顶部)
(1) Configure your JSP
page to display content in utf-8 (place on top of jsp page)
<%@page pageEncoding="utf-8" %>
(2)将默认字符编码设置为utf-8( java系统属性)
(2) Set default character encoding to utf-8 (java system property)
-Dfile.encoding="utf-8"
(3)配置应用程序服务器以在utf-8中编码请求参数(在 conf / server.xml )
(3) Configure your application server to encode request parameters in utf-8 (in conf/server.xml)
<connector .... URIEncoding="utf-8" />
(4) 告诉浏览器内容是在utf-8中(放在html HEAD
部分)
(4) Tell browser content is in utf-8 (place in html HEAD
section)
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
这篇关于设置Java环境(Apache Tomcat)以编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!