One thing that helped was to add to the web-xml
:
<jsp-config>
<taglib>
<taglib-uri>
functions
</taglib-uri>
<taglib-location>
functions.tld
</taglib-location>
</taglib>
</jsp-config>
Now tomcat (7.0.30) sees my taglib which is used to encode URIs.
Strange thing : when I print the username with system out I get ???? in tomcat's console instead of hieroglyphs. Maybe this points to the issue ? In my controller I have :
final String username = Helpers.decodeRequest(request
.getParameter("user"));
System.out.println("ProfileController.doGet() user name DECODED : "
+ username);
where :
private static final String CHARSET_FOR_URL_ENCODING = "UTF-8";
public static String decodeRequest(String parameter)
throws UnsupportedEncodingException {
System.out.println(Charset.defaultCharset()); // EDIT: suggested by @Esailija
if (parameter == null)
return null;
System.out.println("decode - request.getBytes(\"iso-8859-1\"):"
+ new String(parameter.getBytes("iso-8859-1")));
System.out.println("decode - request.getBytes(\"iso-8859-1\") BYTES:"
+ parameter.getBytes("iso-8859-1"));
for (byte iterable_element : parameter.getBytes("iso-8859-1")) {
System.out.println(iterable_element);
}
System.out.println("decode - request.getBytes(\"UTF-8\"):"
+ new String(parameter.getBytes(CHARSET_FOR_URL_ENCODING))); // UTF-8
return URLDecoder.decode(new String(parameter.getBytes("iso-8859-1")),
CHARSET_FOR_URL_ENCODING);
}
So tomcat :
windows-1252 // EDIT: suggested by @Esailija
decode - request.getBytes("iso-8859-1"):╬╡╬╗╬╗╬╖╬╜╬▒╧?╬▒
decode - request.getBytes("iso-8859-1") BYTES:[B@d171825
-50
-75
-50
-69
-50
-69
-50
-73
-50
-67
-50
-79
-49
-127
-50
-79
decode - request.getBytes("UTF-8"):├Ä┬╡├Ä┬╗├Ä┬╗├Ä┬╖├Ä┬╜├Ä┬▒├?┬?├Ä┬▒
ProfileController.doGet() user name DECODED : ╬╡╬╗╬╗╬╖╬╜╬▒╧?╬▒
???????? // user Dao System.out.println("ελληναρα");
com.mysql.jdbc.JDBC4PreparedStatement@67322bd9: SELECT * FROM users WHERE username='╬╡╬╗╬╗╬╖╬╜╬▒╧?╬▒'
ProfileController.doGet() user : null
Eclipse :
UTF-8 // EDIT: suggested by @Esailija
decode - request.getBytes("iso-8859-1"):ελληναρα
decode - request.getBytes("iso-8859-1") BYTES:[B@44c353ae
-50
-75
-50
-69
-50
-69
-50
-73
-50
-67
-50
-79
-49
-127
-50
-79
decode - request.getBytes("UTF-8"):ελληναÏα
ProfileController.doGet() user name DECODED : ελληναρα
ελληναρα // user Dao System.out.println("ελληναρα");
com.mysql.jdbc.JDBC4PreparedStatement@73aae7c6: SELECT * FROM users WHERE username='ελληναρα'
ProfileController.doGet() user : com.ted.domain.User@4b22015d
EDIT : if I change the eclipse encoding in prefs > workspace > text file encoding and set the default (Cp1252)
windows-1252
decode - request.getBytes("iso-8859-1"):λαλακης
decode - request.getBytes("iso-8859-1") BYTES:[B@5ef1946a
-50
// same bytes ....
decode - request.getBytes("UTF-8"):λαλακη�‚
ProfileController.doGet() user name DECODED : λαλακης
ελληναÏ?α
com.mysql.jdbc.JDBC4PreparedStatement@4646ebd8: SELECT * FROM users WHERE username='λαλακης'
ProfileController.doGet() user : null
and Eclipse also fails
NB : Tomcat does print the correct url in the address bar

Eclipse is fine :

Notice that Firefox automatically decodes the Url (to my bewilderment)