I am going mental, international characters that I enter via a form are not being stored exactly as entered and the data stored is not being returned as its stored in the database.
If I enter 'çanak çömlek patladı' and click save on the form I use the page displays 'çanak çömlek patladı' but the database has stored 'çanak çömlek patlad? if I revisit the page again I get 'anak �mlek patlad?'' if I click save on the form without changing anything the database stores '?anak ??mlek patlad?' and the browser displays '?anak ??mlek patlad?'
I have my MySQL Server with the following config:
default-collation=utf8
collation_server=utf8_unicode_ci
character_set_server=utf8
default-character-set=utf8
The database character set is utf8 and database collation is utf8_unicode_ci and the table I am using is set as the same.
The first line of my JSP file is:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
The html header is as so:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
I have an EncodingFilter class compiled which is:
import java.io.IOException;
import javax.servlet.*;
public class EncodingFilter
implements Filter
{
public EncodingFilter()
{
}
public void init(FilterConfig filterconfig)
throws ServletException
{
filterConfig = filterconfig;
encoding = filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain filterchain)
throws IOException, ServletException
{
servletrequest.setCharacterEncoding(encoding);
filterchain.doFilter(servletrequest, servletresponse);
}
public void destroy()
{
}
private String encoding;
private FilterConfig filterConfig;
}
This class is referenced in my web.xml file as follows:
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I’ve restarted my system and therefore the Tomcat and MySQL server, checked the logs and there are no errors with any of the above configuration.
Can anyone please help, otherwise I'll have no hair left?