Configuring a Java environment (Apache Tomcat) for UTF-8 encoding


I want to know how to set up a Java environment for encoding in UTF-8.
Mostly I have JSP pages displayed with some Arabic text, but they don't seem to be correct.
When I run the pages in the IDE, it works fine, but on the server where they are, it just displays it as question marks. I just want to know how to set up a java environment or apache tomcat to encode UTF-8.
Any help would be appreciated.

+5
source share
3 answers

You have several general settings with different exposure levels:

(1) JSP utf-8 ( jsp)

<%@page pageEncoding="utf-8" %>

(2) utf-8 ( java system)

-Dfile.encoding="utf-8"

(3) utf-8 ( conf/server.xml)

<connector .... URIEncoding="utf-8" />

(4) utf-8 ( html HEAD)

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
+23

/config/web.xml : 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>
+4

: "font" , ....

0

All Articles