Reputation: 10137
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");
Upvotes: 0
Views: 5695
Reputation: 242786
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>
Upvotes: 4