I have problem with decoding parameters sent by Flash Player HttpService (data from Spark Form) and received in Java Servlet. This is client code of HttpService and Form:
<mx:HTTPService id="submitForm" result="onResultSend(event)" method="POST" url="{EVMServerConnection.SERVER_ADDRESS}/UserSubmitionServlet" useProxy="false" resultFormat="text">
<mx:request xmlns="">
<login>{login.text}</login>
<password>{password.text}</password>
<email>{email.text}</email>
<userName>{userName.text}</userName>
<secondName>{secondName.text}</secondName>
<gender>{String(gender.selectedItem)}</gender>
<countryKey>{String(country.selectedItem)}</countryKey>
<city>{city.text}</city>
<dateOfBirth>{String(dayOfBirth.selectedItem) + String(monthOfBirth.selectedItem) + String(yearOfBirth.selectedItem)}</dateOfBirth>
</mx:request>
</mx:HTTPService>
The servlet method:
private void registerUser(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
//request.setCharacterEncoding("UTF-16LE");
System.out.println(request.getCharacterEncoding());
String login = request.getParameter("login");
String password = request.getParameter("password");
String email = request.getParameter("email");
//String userName = DataUtils.getUTF8FromUTF16String( request.getParameter("userName") );
//String userName = request.getParameter("userName");
byte[] bytes = request.getParameter("userName").getBytes();
String userName = new String(bytes , "Unicode" );
System.out.println("UserName: " + userName);
String secondName = request.getParameter("secondName");
String gender = request.getParameter("gender");
boolean isMale = false;
if (gender != null)
isMale = !gender.equals("1");
//String countryKey = request.getParameter("countryKey");
String city = request.getParameter("city");
String dateOfBirth = request.getParameter("dateOfBirth");
Date dateDateOfBirth = null;
When I try to display userName on console i get Chinese signs though it should be Polish letters. I tried to use UTF-16, UTF-16LE, UTF-16BE instead of Unicode parameter in new String() but the results were similar.
Helpful was class offered by Apache Tomcat 7, which I am using. I have added SetCharacterEncodingFilter in my web.xml, and now everything works fine and I can read parameters in ordinary way (by String name = request.getParameter(“name”) )