Java&;中的UTF-8解码问题;Tomcat7
我正在向服务器发送一个AJAX请求,其中参数值编码在“escape(…)”函数中 Tomcat服务器(7.0.42)配置为s.t。接收连接器有一个URIEncoding=“UTF-8”,在web.xml中,我配置了SetCharacterEncoding过滤器,如下所示:Java&;中的UTF-8解码问题;Tomcat7,java,character-encoding,tomcat7,httprequest,Java,Character Encoding,Tomcat7,Httprequest,我正在向服务器发送一个AJAX请求,其中参数值编码在“escape(…)”函数中 Tomcat服务器(7.0.42)配置为s.t。接收连接器有一个URIEncoding=“UTF-8”,在web.xml中,我配置了SetCharacterEncoding过滤器,如下所示: <filter> <filter-name>charencode</filter-name> <filter-class> org.apache.
<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>
解析来自拉丁字符集的参数没有问题,但是当我尝试使用俄语时,request.getParameter(..)返回null。此外,我在日志中得到了这个(怀疑它来自SetCharacterEncodingFilter):
并且没有调试级别的消息可遵循(我的记录器设置正确,我相信…)
你能给我个建议吗?会很乐意回答问题的
非常感谢,,
维克多。那个字符串不能解码。与应用服务器无关。请尝试以下工具,以便自己查看: 因此,错误看起来可能是客户端的。确保在URL编码时正确设置了编码。您可能正在使用UTF-8之外的东西,这是您应该使用的
这里有一条关于正确编码unicode字符的线索:谢谢Jilles!这使我走上了正确的道路。另一个关于在JS中编码参数的有用线程:
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
arg1.setCharacterEncoding("UTF-8");
arg2.doFilter(arg0, arg1);
}
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.