我正在向服务器发送 AJAX 请求,其中参数值在“escape(...)”函数中编码。
Tomcat服务器(7.0.42)配置为接收连接器有一个URIEncoding =“UTF-8”,在web.xml中我配置了SetCharacterEncodingFilter如下:
<filter>
<filter-name>charencode</filter-name>
<filter-class>
org.apache.catalina.filters.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charencode</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
,另外我创建了一个过滤器来将响应编码为 UTF-8:
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
arg1.setCharacterEncoding("UTF-8");
arg2.doFilter(arg0, arg1);
}
解析来自拉丁字符集的参数没有问题,但是当我尝试俄语时,request.getParameter(..) 返回 null。此外,我在日志中得到了这个(怀疑它来自 SetCharacterEncodingFilter):
INFO: Character decoding failed. Parameter [usersaid] with value [%u044B%u0432%u0430%u044B%u0432%u0430%u044B%u0432%u044B%u0432%u0430%u044B%u0432%u0430%21] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
并且没有 DEBUG 级别的消息可以跟踪(我相信我的记录器设置正确..)
您能否提一些建议?很乐意回答问题!
非常感谢,维克多。