【发布时间】:2021-02-26 08:07:42
【问题描述】:
每个请求都通过 Microsoft IIS 和一个 AJP13 连接器连接到 Tomcat。一些用户名包含德语特殊字符。如果用户名为“Kloß”,request.getRemoteUser() 返回“KloÃ?”。在 Tomcats localhost_access_log 中,用户名正确记录为“Kloß”。
如何将request.getRemoteUser() 的返回值转换为UTF-8 字符串?
我试过没有成功:
String s1 = request.getRemoteUser()
String s2 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(request.getRemoteUser().getBytes())
【问题讨论】:
-
你试过
new String(s1.getBytes(), "utf-8");吗? -
谢谢!我试过这个。结果与 String s2 中的结果相同
-
你的访问日志编码是什么?我猜它是 ISO-8859-1。
-
访问日志为UTF-8。 “ß”编码为 C3 9f
标签: java tomcat servlets request character-encoding