Search code examples
javajspjstl

What encoding do i need on JSTL c:import for French characters


Im using a generic page header across all my JSPs and pass properties which may be in French or English, however when French properties are passed through with accents i get ? or smililar incorrect characters

<c:set var="subTitle" value="${data}"/>     

<c:import charEncoding="UTF-8" url="../menu/header.jsp" >
        <c:param name="systemTitle" value="${label}" />
    <c:param name="subTitle" value="${subTitle}" />
</c:import>

How do i encode the parameters so they keep their accented characters. UTF-8 doesnt seem to be working unless i have referenced it incorrectly


Solution

  • The <c:import charEncoding> merely instructs the <c:import> what character encoding it should use to read the target resource. It doesn't instruct what character encoding it should use to write the read characters to the response body. Instead, the JSP page's own character encoding is been used for that. You can set it by adding the following line to the very top of the JSP:

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

    Note that you can also set it applicationwide (which is recommended if you want World Domination) by adding the following entry to web.xml:

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <page-encoding>UTF-8</page-encoding>
        </jsp-property-group>
    </jsp-config>