I have a list in my action which I field by values saved on a MySql DB.
I only have one object stored, which has designation €
.
In jsp when I do
If the page encoding is not defined, the default is (the equivalent of the JSP page
directive):
<%@page contentType="text/html; charset=ISO-8859-1" %>
The encoding you want is not ISO-8859-1
, but UTF-8
, that supports any language (take a look at Table 23-2 Valid Values for the IANA-Defined Character Set).
You can set your page, request and response encoding in three ways:
Setting the contentType
in each JSP:
<%@page contentType="text/html; charset=UTF-8" %>
Setting the pageEncoding
in each JSP:
<%@page pageEncoding="UTF-8" %>
Setting the <jsp-property-group>
once in web.xml:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
The HTML <meta>
tag will be generated accordingly. Remember to not specify different encodings when unnecessarily using both pageEncoding
and <jsp-property-group>
, it is a translation-time error.
For more info about this, read the Oracle docs (pretty old, but still true).
Place this on the top of the JSP page. Symbols in UTF-8 encoding displays better than ?
.
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>