解决 post 请求乱码:我们可以在 web.xml 里边配置一个 CharacterEncodingFilter 过滤器。 设置为 utf-8。
解决 get 请求的乱码:有两种方法。对于 get 请求中文参数出现乱码解决方法有两个:
- 修改 tomcat 配置文件添加编码与工程编码一致。
- 另一种方法对参数进行重新编码
String userName = New String(Request.getParameter(“userName”).getBytes(“ISO8859-1”), “utf-8”);