For decoding URIs correctly, you need URIEncoding connector attribute in Tomcat:
<connector ... URIEncoding="UTF-8" ... />
See my rant https://stackoverflow.com/a/15587140/995876
So it doesn't come with normal code, you need it in the application server configuration separately or use an application server that defaults to UTF-8. There is no way to affect this from code unfortunately.
Drop the decodeRequest
and never use new String/getBytes
without explicit encoding argument.
Alternative.
If you can't edit the server connector configuration, you can fix your code by providing the encoding explicitly to new String
:
public static String decodeRequest(String parameter) {
return new String(parameter.getBytes("iso-8859-1"), "UTF-8");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…