I am doing a simple ajax call with the YahooUI Javascript library as follows:
YAHOO.util.Connect.setForm(\'myform\');
YAHOO.util.Connect.asyncRequest(\'POST\
Since you are using a POST
query, URIEncoding="UTF-8"
is not applicable here. You need to set a filter to tell Tomcat that your request encoding is UTF-8. You may use, for example, a Spring's CharacterEncodingFilter
(usage, javadoc). Other implementations of such filters can also be found.
Yes, here is one:
package com.lfantastico.web;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class EncodingFilter implements Filter {
private String encoding = "UTF-8";
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
if (config.getInitParameter("encoding") != null) {
encoding = config.getInitParameter("encoding");
}
}
}