UTF-8 encoding in Spring MVC, problem with FORMs

05-05-2015

Question:

I have this in web.xml

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

and at the top of file.jsp I have this:

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

in this:

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

and characters other than latin-1 set from FORM with method POST are still not correct.

Answer

I solved this.

That filter in web.xml must be first filter in file.

© 2019 All rights reserved. Codesenior.COM