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.
Asked
Active
Viewed 2.1k times
5

Mush
- 185
- 1
- 2
- 12
-
1a related post might help http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps – Umer Hayat Sep 27 '11 at 09:39
3 Answers
24
You have a few general settings with different impact levels:
(1) Configure your JSP
page to display content in utf-8 (place on top of jsp page)
<%@page pageEncoding="utf-8" %>
(2) Set default character encoding to utf-8 (java system property)
-Dfile.encoding="utf-8"
(3) Configure your application server to encode request parameters in utf-8 (in conf/server.xml)
<connector .... URIEncoding="utf-8" />
(4) Tell browser content is in utf-8 (place in html HEAD
section)
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

Johan Sjöberg
- 47,929
- 21
- 130
- 148
-
these steps have been explained in detail in an old post http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps – Umer Hayat Sep 27 '11 at 09:40
-
1@Mush, as an argument to starting your server, typically by setting the `JAVA_OPTS="-D..."` variable e.g., in the startup script or as a system variable (`export JAVA_OPTS=".."`). – Johan Sjöberg Sep 27 '11 at 10:39
-
4
You must to edit the /config/web.xml uncomment this filter: setCharacterEncodingFilter
<!-- A filter that sets character encoding that is used to decode -->
<!-- parameters in a POST request -->
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<!-- The mapping for the Set Character Encoding Filter -->
<filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Rodrigo Araujo
- 1,062
- 1
- 9
- 8
0
In within your project directory: You must have a folder named 'font' in this foler copy the arabic fonts , this will carry your path to characters on server too....

kulss
- 2,057
- 1
- 14
- 16