Encoding post data on Tomcat 7 using 2.0.3 corrupted
ejb3workshop Aug 26, 2013 1:35 AMI am trying to post UTF-8 encoding text to my JSF2.2 application, however the data received does not seem to be encoded correctly.I narrowed this problem down to the weld listener. To illustrate the issue I created a simple jsp page:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Character encoding test page</title> </head> <body> <p> Encoding : <%=request.getCharacterEncoding()%> </p> <p>Data posted to this form was: <% request.setCharacterEncoding("UTF-8"); out.print(request.getParameter("mydata")); %> </p> <form method="GET" action="index.jsp"> <input type="text" name="mydata"> <input type="submit" value="SubmitGET" /> </form> <form method="POST" action="index.jsp"> <input type="text" name="mydata"> <input type="submit" value="SubmitPOST" /> </form> .g. ç,ğ,ö,ş,ı, etc Soße “ Test data ” </body> </html>
So I have a simple web application which only consist of this page, and the weld library in WEB-INF/lib (weld-servlet-2.0.3.Final.jar).
So far so good. However as soon as I include the weld listener in my web.xml file
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app>
The post parameters are corrupted by the listener.
I did enable URIEncoding="UTF-8" in the server.xml file, but this did not make any difference.
<Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>
With the listener enabled data like "Soße" is received as "Soße", however once the listerner is removed everything works as expected.