I have a very strange issue, I have two web apps running on the same Tomcat 6 instance. However one web app posts UTF-8 characters correctly and the other web app doesn't and I can't figure out why.
The server.xml file has the line:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" />
Each WEB-INF/web.xml has the following lines:
<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>
<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>
Each web app has the same java class EncodingFilter located in the WEB-INF\classes folder, the java class is as follows:
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;
}
I have checked the JAVA environment settings:
file.encoding=UTF-8
sun.jnu.encoding=UTF-8
sun.io.unicode.encoding=UnicodeLittle
file.encoding.pkg=sun.io
But here is the kicker the following JSP file posts correctly in one web app but not the other:
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Character encoding test page</title>
</head>
<body>
<p>Data posted to this form was:
<%
request.setCharacterEncoding("UTF-8");
out.print(request.getParameter("mydata"));
%>
</p>
<form method="POST" action="test.jsp">
<input type="text" name="mydata">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</body>
</html>
If I post 'çanak çömlek patladı' in one I get 'çanak çömlek patladı', if I post in the other web app I get 'çanak çömlek patladı' I really can't understand why, they both use the same files, on the same Tomcat instance, so why on earth am I getting a different result, what could be hidden that I am missing?
Any help would be much appreciated :-)