在您的示例中,表单使用%编码将“á”的UTF-8字符发送给Tomcat(因此,它是%C3%A1)。但是,Tomcat将其解释为Latin1,这是POST的默认编码。
因此,Tomcat将在内部将C3A1存储为“Ô,因为在Latin1编码中C3为“Ô,而A1为“¡”。
当您要求输入username.getBytes()时,它将创建一个UTF-8编码的字节数组,因此它将在UTF-8字符集C383
C2A1中查找两个字符’á’。
详细描述此问题的FAQ和建议的解决方案:http
:
//wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q3
在server.xml中更改FormAuthenticator的Valve以指定
characterEncoding="UTF-8"
<Context path="/YourSercureApp"> <Valve className="org.apache.catalina.authenticator.FormAuthenticator" disableProxyCaching="false" characterEncoding="UTF-8" /> </Context>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)