views:

212

answers:

1

Hello I have a jsp with an html form.

I set the content type like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>

When I send special characters like á é í ó ú they are saved correctly in the database. My table charset is utf-8.

I want to change iso-8859 to utf-8 like this to standardize my application and accept more special characters:

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

but when I change it to utf-8 the special characters á é í ó ú are not saved correctly in the databse. When I try to save á it is saved as á

In the server side I'm using Spring MVC. I'm getting the text field value like this:

String strField = ServletRequestUtils.getStringParameter(request,
                    "field");
+2  A: 

When your pages are not ISO-8859-1, you need to declare a CharacterEncodingFilter in web.xml:

<filter>
    <filter-name>charsetFilter</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>
</filter>

<filter-mapping>
    <filter-name>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
axtavt
I have tried that and still getting á instead of á
Enrique
I just moved the filter at the beginning of web.xml and it works now!! however I some special characters like ♫ are changed with questions marks ?
Enrique